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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 HELP!Why my SQL clause cann't work?

Author  Topic 

sunnykj
Starting Member

29 Posts

Posted - 2006-07-31 : 02:21:21
Master,Why my SQL clause cann't work?

DELETE FROM Orders AS A WHERE A.OrderID = 10248

It's unbelievable!

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2006-07-31 : 02:28:37
What happens when you run this:

SELECT * FROM Orders WHERE OrderID = 10248

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-31 : 02:29:43
[code]DELETE A FROM Orders AS A WHERE A.OrderID = 10248[/code]


KH

Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-31 : 02:30:34
or
DELETE FROM Orders AS A WHERE A.OrderID = 10248



KH

Go to Top of Page

sunnykj
Starting Member

29 Posts

Posted - 2006-07-31 : 02:42:41
Thank you for your answer.But,Why the alias'A' in 'DELETE A' is necessary?
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-07-31 : 02:44:35
it is necessary if you use alias.


KH

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-07-31 : 04:55:37
"Why the alias'A' in 'DELETE A' is necessary?"

Consider this:
[CODE]
DELETE A
FROM MyTable1 AS A
JOIN MyTable2 AS B
ON B.ID = A.ID
WHERE A.SomeColumn = 10248
[/CODE]
SQL needs to know which table to delete from. Its unambiguous with only one table, hence you can do

DELETE MyTable1
WHERE A.SomeColumn = 10248

but I always write my deletes using FROM and an ALIAS so they are consistent (i.e. whether they have a JOIN or not)

Kristen
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-08-01 : 03:24:19
quote:
Originally posted by khtan

or
DELETE FROM Orders AS A WHERE A.OrderID = 10248

Or even simpler
DELETE Orders WHERE OrderID = 10248



Peter Larsson
Helsingborg, Sweden
Go to Top of Page
   

- Advertisement -