Click here to Skip to main content
15,898,373 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all,

i've two Tables(table1,table2).
table1 columns(column1(primary key),column2,column3).

table2 columns(tabcol1,tabcol2,column1(Foreign key)).

my question is how to write sql query to update both table columns data except primary key column.please reply with an exp.
Posted
Comments
m@dhu 27-Jan-11 7:38am    
Use a SP to do it.

INSERT INTO table1
(column1, column2, column2);

DECLARE @PK int;

SELECT @PK = 
(
   SELECT MAX(column1) 
   FROM table1
)

INSERT INTO table2
(tabcol1, tabcol2, @PK);
 
Share this answer
 
v2
Google "t-sql insert update table". Essentially, you'll need a minimum of two statements in a stored procedure, and dpending on whether you're updating existing data or inserting new data, you'll want to use update or insert, whichever is appropriate.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900