Hi
Dudes
is it possible can i update, insert in Sql Server 2005 more than one tables in one query...................? if it is possible can any one help me...?
Loading
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
Suthish NairRank #92 · 22.8K reputationPosted Jul 27, 2011, 2:52 AM EDT
VulpesRank #55 · 29.2K reputationPosted Jul 27, 2011, 3:00 AM EDT
Zoran HorvatRank #792 · 2.9K reputationPosted Jul 27, 2011, 3:08 AM EDT
However, you can update data from views that join multiple tables. For example, consider these tables and a view that joins them:
CREATE TABLE A (
AID INT PRIMARY KEY IDENTITY(1, 1),
AName VARCHAR(100)
);
CREATE TABLE B (
BID INT PRIMARY KEY IDENTITY(1, 1),
AID INT FOREIGN KEY REFERENCES A(AID),
BName VARCHAR(100)
);
CREATE VIEW V AS
SELECT A.AID, AName, BID, BName FROM A INNER JOIN B ON A.AID=B.AID;
Here if you insert data like this:
INSERT INTO A(AName) VALUES ('One');
INSERT INTO B(AID, BName) VALUES (1, 'Two');
You can update values in B row like this:
UPDATE V SET BName='Updated' WHERE AID=1;
This will work because source of the BName column is known and it can be updated by this statement. At the same time, INSERT fails on the same view:
INSERT INTO V(AName, BName) VALUES ('One', 'Two');
This statement would require SQL Server to determine AID which was created by inserting row into A table, and then to use that value as a foreign key to B table. However, this statement doesn't contain sufficient information for SQL Server to understand that it is exactly the one value of AID that should be inserted into B table, hence such statement is not legal.
Zoran