Click here to Skip to main content
15,902,634 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 3 tables like

table A//user
Aid(pk) content locked

table B//article
Bid(pk) Aid(fk) content locked

table C//comment
Cid(pk) Bid(fk) content locked

i want to update the column locked value as 1
where Aid=xx (tableA)

in tableB
all Aid column with matching value xx then locked value as 1

in tableC
all Bid column with affected tableB then locked value as 1

pk-- primary key
fk-- foreign key

thanks in advance
Posted
Updated 30-Nov-12 22:34pm
v3

1 solution

Quote:
i want to update the column locked value as 1
where Aid=xx (tableA)

SQL
UPDATE tableA
SET locked = 1
WHERE Aid = [some value]




Quote:
in tableB
all Aid column with matching value xx then locked value as 1

SQL
UPDATE tableb, tablea
SET tableb.Locked = 1
WHERE tablea.Aid = tableb.Aid and tablea.Aid = [some value]




Quote:
in tableC
all Bid column with affected tableB then locked value as 1

SQL
UPDATE tableb, tablea,tablec
SET tablec.Locked = 1
WHERE tablea.Aid = tableb.Aid 
and tableb.Bid = tablec.Bid
and tablea.Aid = [some value]


You can also take a look at the below links
Mastering the SQL UPDATE Statement[^]
UPDATE Basics in SQL Server[^]

Hope this helps.
 
Share this answer
 
v3
Comments
mohanrajkiller 1-Dec-12 3:55am    
is that possible to do all in one query
__TR__ 1-Dec-12 4:28am    
You cannot update multiple tables in a single update statement. However you can use transactions so that if any of the update statement fails everything gets roll backed.
mohanrajkiller 1-Dec-12 4:34am    
can you convert this for mysql
__TR__ 1-Dec-12 5:53am    
Updated the solution for MsSQL.
mohanrajkiller 1-Dec-12 6:03am    
works thanks can you answer my next question :(

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