Joe M Joe M - 3 months ago 8
SQL Question

Difference between DELETE and DELETE FROM in SQL?

Is there one? I am researching some stored procedures, and in one place I found the following line:

DELETE BI_Appointments
WHERE VisitType != (
SELECT TOP 1 CheckupType
FROM BI_Settings
WHERE DoctorName = @DoctorName)


Would that do the same thing as:

DELETE FROM BI_Appointments
WHERE VisitType != (
SELECT TOP 1 CheckupType
FROM BI_Settings
WHERE DoctorName = @DoctorName)


Or is it a syntax error, or something entirely different?

Answer

Assuming this is T-SQL or MS SQL Server, there is no difference and the statements are identical. The first FROM keyword is syntactically optional in a DELETE statement.

http://technet.microsoft.com/en-us/library/ms189835.aspx

Note that your example subqueries are potentially non-deterministic since there is no ORDER BY clause.

Comments