 



%%%%%%%%%%%%%%%%%%%%%%%%%%%
% TABLE  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

table(Name,Id_table):-data(_,Name,_,Id_table).
table(Name,Id_table):-role(Name,true,_,*,_,Id_table).


  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ROW-STORE  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

row-store(Name,Id_table,[Id_table,Id_row]):-
				data(Name,_,Id_row,Id_table).
				 

%%%%%%%%%%%%%%%%%%%%%%%%%%
% ROW-MIX  
%%%%%%%%%%%%%%%%%%%%%%%%%	

row-mix(NameR,Id_table,[Id_table,Id_row]):-
		role(Name,true,_,*,_,Id_table),
		is_data(Id_table,Id_row),
		data(NameD,_,Id_row,_),
		atom_concat(Name,NameD,NameR).
				
					 

%%%%%%%%%%%%%%%%%%%%%%%%%
% ROW
%%%%%%%%%%%%%%%%%%%%%%

row(Name,Id_table,Id_row):-row-store(Name,Id_table,Id_row).
row(Name,Id_table,Id_row):-row-mix(Name,Id_table,Id_row).
		
 				 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% COLUMN 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%	
		 
key(Name,Type,[Id_table,Id_row],[Id_table,Id_row,Id_column]):-
				row-store(_,_,[Id_table,Id_row]),
				attribute(Name,Type,true,Id_row,Id_column).

col(Name,Type,[Id_table,Id_row],[Id_table,Id_row,Id_column]):-
				row-store(_,_,[Id_table,Id_row]),
				attribute(Name,Type,false,Id_row,Id_column).

foreign(NameF,Type,[Id_table,Id_row],[Id_table,Id_row,Id_column]):-
				is_role(Id_relation,Id_table),
 				row-mix(NameR,Id_table,[Id_table,Id_row]),			
				role(_,_,_,_,Id_relation,Id_qualifier),				 
				qualifier(NameQ,Type,Id_qualifier,Id_column),
				atom_concat(NameR,NameQ,NameF).

 
 
 


