|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
||||
|
||||
|
I am trying to do something impossible with a single SQL statement. I am doing an ASP webpage for internal use at the company I work for.
I want to know if there is a way to insert/update data into multiple tables in <b>1</b> SQL statement. If it requires functions | views or anything else that is fine but I don't want to have 3-4 different SQL statements to update 2-3 different columns in different tables. Thanks, Gerbill BTW I posted this in the ASP forum but was told I could get some help over here. I am currently working on a stored procedure to possibly fix my problem... |
|
#2
|
|||
|
|||
|
I don't see why it must be one statement. If you need to execute multiple statements as one indivisable unit, use transactions
Code:
begin transaction insert ... if @@error <> goto rbck update if @@error <> goto rbck ... commit transaction return 0 rbck: rollback transaction You can put it all into a stored procedure to get better performance. |
|
#3
|
||||
|
||||
|
Yeah I am currently fixing up a nice stored procedure to do this but...
is it at all possible to have one SQL statement that will update 2 or more columns in different tables. The tables are linked through PK & FK so that is no problem. I don't think that is possible but I was feeling lazy and thought I would give it a shot. Thanks, Gerbill |
|
#4
|
|||
|
|||
|
An update statement can only update one table/view. There are limitations when updating join views.
Quote:
You can update multiple tables by using instead of triggers. (Read more in BOL.) You still have to write individual update statements for each base table. |
|
#5
|
||||
|
||||
|
Yep just like I thought. Oh well maybe in the next version they will introduce the ability to insert/update multiple tables in one SQL statement.
Just like a select you have to specify the tableName.ColName but hey it would be great Later, Gerbill |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Insert/Update multiple columns in multiple tables |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|