#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Posts
    169
    Rep Power
    37

    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
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    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.

    Clive
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2007
    Posts
    169
    Rep Power
    37

    Re


    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.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Jan 2006
    Location
    Carlsbad, CA
    Posts
    2,057
    Rep Power
    383
    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.

    Clive

IMN logo majestic logo threadwatch logo seochat tools logo