March 14th, 2012, 06:36 AM
Compare to tables
Is there a way to compare to tables to eachother. Let say i have a table [A] with Field 1[FF01:string], Field 2 [FF02:string] and table [B] with Field 1[FF01:string], Field 2 [FF02test:string].
So in table B the 2nd fieldname not the same as table A. Then i want to RAISE AN EXCEPTION.
Is there a way to, if i want to, to check each fieldname as above, and maybe the types?
Thanks in advance
March 14th, 2012, 12:29 PM
Yes; but it depends
Do you need to do this through pure SQL or will you access the tables via a TDataset?
If the former, then you will have to learn about the meta data tables and views of
the specific SQL database (and possibly version) that you are using and construct suitable
queries to obtain the information you need.
If the latter (TDataset) then, as I mentioned in another thread, you need to work with the Fields property of TDataset which will give you access to everything you need.
March 15th, 2012, 10:57 AM
I would like to do if with SQL.
A while loop wil take so long if there is 50 plus fields. Or can i just do a insert into statement do a try and except if i get an error i know there is a problem. But its a silly way of doing it. If i can do a fix on the 2nd tabel adding the fieldnames automatically.IT WILL BE GREAT.
March 15th, 2012, 01:48 PM
If you do not / can not do the comparison using TDataset or other Delphi classes then you are going to have to do your own research.
The queries to obtain the information you need for comparison will depend on the SQL database you are using.
It may also determine what user privileges you need.
The built in programming language will also be different and have vastly different feature sets.
Finally, if you actually want to change field names you will probably have a whole host
of additional privileges to consider and you may need exclusive access to the table
in question. Obviously, changing field names will invalidate any internal or external code
that accesses the table; but I presume you are aware of that issue.