-2

I have a table 'Department' inside a database and I would like to delete some rows. I would like to ask if

The result of this SQL delete code:

DELETE FROM ITD
FROM Department AS ITD
WHERE ITD.departmentID = 1

is it the same as the result of this:

DELETE FROM Department 
WHERE departmentID = 1

Does both codes delete those entry in the table?

4

1 回答 1

2

The both are the same. The first FROM is optional.

In Short, We use the syntax 1 to specify the table from which data has to be deleted if the condition for deleting the data involves using two tables.

delete from t1
    where exists (
   select t2.some_id
     from t2
    where t2.some_id = t1.some_id );

This can be written as

delete from t1
 from t1, t2
where t1.some_id = t2.some_id;

Hope it is clear now. For more information see the MSDN link

于 2013-05-20T05:54:08.857 回答