Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
rudba
Constraint Violating Yak Guru
415 Posts |
Posted - 2010-04-01 : 15:00:14
|
| Is there a way to delete data from multiple tables in a single query?I want to delete @tbl1 and @tbl2 where StudentID=101declare @tbl1 table( StudentID int, fname varchar(10))INSERT INTO @tbl1SELECT 101, 'AA'INSERT INTO @tbl1SELECT 102,'BB'declare @tbl2 table( ID int, StudentID int)INSERT INTO @tbl2SELECT 1, 101INSERT INTO @tbl2SELECT 2,102INSERT INTO @tbl2SELECT 3, 102INSERT INTO @tbl2SELECT 4,101select * from @tbl1select * from @tbl2 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2010-04-01 : 15:08:21
|
| You might be able to using the MERGE statement (I know you can insert into two at once). Since you are a "Constraint Violating Yak Guru," you should give it a try! :)EDIT: Thought I was in a 2008 forum.. I guess you can't since MERGE is 2008.But, my question is why would you need/want to do that? |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
rudba
Constraint Violating Yak Guru
415 Posts |
Posted - 2010-04-01 : 17:12:40
|
| they are related but there is not set foreign keys. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|
|
|
|
|