Trupti
Trupti

Reputation: 627

How to update more than one table in one update statement

I am updating one column in a table from details view control of .net 3.5 and using SQL Server 2005

The problem is I have to update same column in 5 more tables in the same database but have to use single database

Is it possible?

please let me know the SQL query syntax form update if possible.

Upvotes: 0

Views: 193

Answers (2)

Dhananjay
Dhananjay

Reputation: 3793

There are work arounds.

  1. create a view such that it has 5 table joins and a select statement on 5 columns. Then update the view.

  2. Write update trigger on table 1 and in the trigger write update for table2...continue.

I have not tried this before, so just first give a try.

Upvotes: 1

juergen d
juergen d

Reputation: 204924

You can't update 5 different tables in one update query.

You can write a stored procedure that updates that 5 tables and call that procedure once.

Upvotes: 4

Related Questions