INSERT INTO with FOREIGN KEY ???
- From: "." <someone@xxxxxxxxxxxx>
- Date: Thu, 4 May 2006 00:36:30 +0200
Hello,
I can't figure out how to manage INSERT INTO in a table having FOREIGN KEY
constraint.
For ex, with ADO, I sent these 2 SQL Commands :
CREATE TABLE Try1(pKTry1 IDENTITY NOT NULL PRIMARY KEY, strValue
nvarchar(10))
CREATE TABLE Try2(pkTry2 IDENTITY NOT NULL PRIMARY KEY, fKTry1 int NOT NULL
strValue2 nvarchar(10), CONSTRAINT fk_Try2_Try1 FOREIGN KEY fKTry1
REFERENCES Try2.fKTry1=Try1.fkTry1)
which create 2 tables with table Try2 having a foreign key.
I populate Try1 with
INSERT INTO Try1(strValue) VALUES('Dummy1')
Now, I need to populate table Try2.
Actually, I use ADO recordset to retreive primary key from Try1.
rstSQL.OPEN "SELECT pKTry1 FROM Try1 WHERE (strValue='Dummy1')"
lngpK = rstSQL("pKTry1").Value
and then
cmdSQL.commandText = "INSERT INTO Try2(fkTry2, strValue2) VALUES(" & lngpK &
",'Dummy2')"
cmdSQL.Execute
This pCode works at the price of an increase in total requests to the server
and implies that the client manages all "string concatenation".
I know that there is a Server side solution to this problem but I don't know
how to manage it with an Access Database (ie no multiline stored procedure).
I try without any success something like
INSERT INTO Try2(fkTry2, strValue2) VALUES((SELECT pKTry1 FROM Try1 WHERE
strValue="Dummy1'),'Dummy2')" => resulting with an ADO error message ???
Any ideas and all help appreciate
TIA
.
- Follow-Ups:
- Re: INSERT INTO with FOREIGN KEY ???
- From: Stephen Howe
- Re: INSERT INTO with FOREIGN KEY ???
- Prev by Date: kb838405
- Next by Date: Re: INSERT INTO with FOREIGN KEY ???
- Previous by thread: kb838405
- Next by thread: Re: INSERT INTO with FOREIGN KEY ???
- Index(es):
Relevant Pages
|
|