Article View: borland.public.cppbuilder.database.ado
Article #2178Two more problems in sql related to inserting data into related tables
From: Ted Byers
Date: Fri, 31 Oct 2003 22:43
Date: Fri, 31 Oct 2003 22:43
28 lines
2339 bytes
2339 bytes
How do I (in pure SQL): 1) ensure that, if I have two values, one of which is an autoincremented integer that provides the primary index for the table, the values in the second field are unique? i.e., imagine a table with two fields, x and y, and y is text while x is an autoincremented integer. x is guaranteed to be unique but I also need y to be unique. 2) determine if a given string is present in the table mentioned in item 1, and if it is not insert it, and, either way, get the value of x corresponding to the value of y and insert that along with any other available data for a second table where x from the first table is identified as a foreign key? I know how to do the second part of this where the relevant index is known at compile time (i.e. trivial tests involving inserting data into the lookup table and then just hard coding the index, (i.e. the value 1) for the first item inserted into the lookup table, into the insert statement for the second table, but I don't know the more general solution when you have no idea whether or not the value to be looked up inthe lookup table is in it already and, either way, what its index is. The general problem I am trying to solve using SQL is how to add data to a pair (or more) of tables linked with one to many relationships. And, a constraint is that it must be SQL code I can pass to the database using an ADODB.Connection! Thanks, Ted
Technical Details
Message-ID:
<3fa2e621$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,a8d9c64ca65c14af,start X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2003-10-31 15:09:25 PST From: "Ted Byers" <r.ted.byers@sympatico.ca> Newsgroups: borland.public.cppbuilder.database.ado Subject: Two more problems in sql related to inserting data into related tables Date: Fri, 31 Oct 2003 17:43:10 -0500 Lines: 30 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 65.95.126.104 Message-ID: <3fa2e621$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1067640353 65.95.126.104 (31 Oct 2003 14:45:53 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail