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
 General SQL Server Forums
 New to SQL Server Programming
 Syntax Question

Author  Topic 

hh1234
Starting Member

30 Posts

Posted - 2011-10-27 : 15:57:52
The following syntax works when run on the SQL Server.

Select * From v_R_System Netbios_Name0
Where Netbios_Name0 = 'hou-lt-44'

When run this will display one result and this result has all the information on machine hou-lt-44.



If I run this, will it "Only" delete this one record?

Delete * From v_R_System Netbios_Name0
Where Netbios_Name0 = 'hou-lt-44'



What scared the hell out of me is the '*' in the delete command. That tells me get EVERYTHING and I can't delete all of our clients. So I want to make sure.

Thank you.

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2011-10-27 : 16:19:40
I don't believe that you could run that delete statement. A delete statement does not take a <column list>. Just:
Delete
FROM...
WHERE...

or

DELETE <table or tableAlias>
FROM...
WHERE

Be One with the Optimizer
TG
Go to Top of Page

hh1234
Starting Member

30 Posts

Posted - 2011-10-27 : 16:45:13
Delete FROM v_R_System
Where Netbios_Name0 = 'hou-lt-44"

Is that what the syntax is?
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2011-10-27 : 17:15:24
if v_R_System is a table and Netbios_Name0 is a column then yes.
However looks like you've got a double quote closing your constant instead of a single quote.

try to parse the statement in a query window in Management Studio. (the little check mark in the tool bar)

Be One with the Optimizer
TG
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2011-10-27 : 17:17:11
Also, a good practice when DELETing data is to first replace the "DELETE" with "SELECT *". That way you can see exactly what you are about to delete. Particularly helpful if you happen to forget your WHERE clause :)

Be One with the Optimizer
TG
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-10-27 : 17:35:57
using an alias makes thing more readable and safer

DELETE e
FROM
Employees AS e
JOIN EmployeeDepartments AS ed ON ed.[EmployeeID] = e.[EmployeeID]
JOIN Departments AS d ON d.[DepartmentID] = ed.[DepartmentID]
WHERE
d.[DepartmentName] = 'Sales'

which will delete all employees that are members of the Sales department

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2011-10-27 : 19:02:04
Charlie, I've tried that statement and it doesn't work. The Sales guys are still here

Be One with the Optimizer
TG
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2011-10-27 : 20:19:09
you have to commit

Charlie
===============================================================
Msg 3903, Level 16, State 1, Line 1736
The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2011-10-27 : 22:38:20
Is he married? Or Engaged? Thats kinda personal don't you think?

Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx


Want to help yourself?

http://msdn.microsoft.com/en-us/library/ms130214.aspx

http://weblogs.sqlteam.com/brettk/

http://brettkaiser.blogspot.com/


Go to Top of Page
   

- Advertisement -