SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Delete from multiple tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

kwacz23
Starting Member

44 Posts

Posted - 11/05/2013 :  03:58:57  Show Profile  Reply with Quote
Hi

Can you help me with below query? I would like to delete records from 3 tables in one query

i am trying below:

DELETE dbo.ExtAttribute , dbo.ExtAttributeValue FROM dbo.ExtAttributeProduct
INNER JOIN dbo.ExtAttribute ON dbo.ExtAttributeProduct.AttributeId = dbo.ExtAttribute.Id
INNER JOIN dbo.ExtAttributeValue ON dbo.ExtAttributeValue.AttributeId = dbo.ExtAttributeProduct.AttributeId
WHERE ProductId = 'GPTEST_NEW'

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 11/05/2013 :  04:22:17  Show Profile  Reply with Quote
you cant. you need to write separate DELETE statements for that

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

suryayadav
Starting Member

India
4 Posts

Posted - 11/07/2013 :  06:56:54  Show Profile  Reply with Quote
yes u can
heres the code

delete from <table1>,<table2>,<table3>,<table4>

surya
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 11/07/2013 :  07:21:17  Show Profile  Reply with Quote
quote:
Originally posted by suryayadav

yes u can
heres the code

delete from <table1>,<table2>,<table3>,<table4>

surya


where did you get this from?
did you test it for any actual tables?
try below code and see what you get

CREATE TABLE #t1
(
ID int,
Val varchar(5)
)

CREATE TABLE #t2
(
ID int,
Val varchar(5)
)

INSERT #t1
VALUES(1,'xxx'),(2,'ewfe')

INSERT #t2
VALUES(1,'xxx'),(2,'ewfe'),(3,'klhiohj')

DELETE FROm #t1,#t2

probably you meant drop instead of DELETE

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

sgondesi
Posting Yak Master

India
193 Posts

Posted - 11/08/2013 :  04:18:57  Show Profile  Reply with Quote
quote:
Originally posted by visakh16

quote:
Originally posted by suryayadav

yes u can
heres the code

delete from <table1>,<table2>,<table3>,<table4>

surya


where did you get this from?
did you test it for any actual tables?
try below code and see what you get

CREATE TABLE #t1
(
ID int,
Val varchar(5)
)

CREATE TABLE #t2
(
ID int,
Val varchar(5)
)

INSERT #t1
VALUES(1,'xxx'),(2,'ewfe')

INSERT #t2
VALUES(1,'xxx'),(2,'ewfe'),(3,'klhiohj')

DELETE FROm #t1,#t2

probably you meant drop instead of DELETE

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs




sir,
i am getting below mentioned error when i tried to execute the code posted by you.

Msg 102, Level 15, State 1, Line 23
Incorrect syntax near ','.


--
Thanks and Regards
Srikar Reddy Gondesi,
BTECH-IT 2013 Passed Out,
Trainee for SQL Server Administration,
Miracle Software systems, Inc.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 11/08/2013 :  04:46:00  Show Profile  Reply with Quote
quote:
Originally posted by sgondesi

quote:
Originally posted by visakh16

quote:
Originally posted by suryayadav

yes u can
heres the code

delete from <table1>,<table2>,<table3>,<table4>

surya


where did you get this from?
did you test it for any actual tables?
try below code and see what you get

CREATE TABLE #t1
(
ID int,
Val varchar(5)
)

CREATE TABLE #t2
(
ID int,
Val varchar(5)
)

INSERT #t1
VALUES(1,'xxx'),(2,'ewfe')

INSERT #t2
VALUES(1,'xxx'),(2,'ewfe'),(3,'klhiohj')

DELETE FROm #t1,#t2

probably you meant drop instead of DELETE

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs




sir,
i am getting below mentioned error when i tried to execute the code posted by you.

Msg 102, Level 15, State 1, Line 23
Incorrect syntax near ','.


--
Thanks and Regards
Srikar Reddy Gondesi,
BTECH-IT 2013 Passed Out,
Trainee for SQL Server Administration,
Miracle Software systems, Inc.


Exactly
That was my point

you CANT delete data from multiple tables using single DELETE

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

sgondesi
Posting Yak Master

India
193 Posts

Posted - 11/08/2013 :  05:17:33  Show Profile  Reply with Quote
Ok sir.
thank you.

--
Thanks and Regards
Srikar Reddy Gondesi,
BTECH-IT 2013 Passed Out,
Trainee for SQL Server Administration,
Miracle Software systems, Inc.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.08 seconds. Powered By: Snitz Forums 2000