Article View: borland.public.cppbuilder.database.ado
Article #2180Re: Two more problems in sql related to inserting data into related tables
From: Viatcheslav V. Vassiliev
Date: Sat, 01 Nov 2003 07:14
Date: Sat, 01 Nov 2003 07:14
54 lines
3239 bytes
3239 bytes
1) Create unique constraint for second field. 2) On server-side cursor, use Seek on indexed field, on client-side you may use Locate() if you work with ADO Express (dbGo). > 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. Execute 2 insert queries, possibly inside transaction - look ADO documentation on how to do this - you may find it in MSDN. //------------------------------------------ Regards, Viatcheslav V. Vassiliev http://www.managed-vcl.com http://www.oledbdirect.com "Ted Byers" <r.ted.byers@sympatico.ca> �������/�������� � �������� ���������: news:3fa2e621$1@newsgroups.borland.com... > 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:
<3fa37cec$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-mailReferences:
<3fa2e621$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 10698b,a8d9c64ca65c14af X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2003-11-01 01:39:23 PST From: "Viatcheslav V. Vassiliev" <support@oledbdirect.com> Newsgroups: borland.public.cppbuilder.database.ado References: <3fa2e621$1@newsgroups.borland.com> Subject: Re: Two more problems in sql related to inserting data into related tables Date: Sat, 1 Nov 2003 10:14:22 +0300 Lines: 56 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 213.234.218.42 Message-ID: <3fa37cec$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1067678956 213.234.218.42 (1 Nov 2003 01:29:16 -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