| 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_Name0Where 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_Name0Where 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...WHEREBe One with the OptimizerTG |
 |
|
|
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? |
 |
|
|
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 OptimizerTG |
 |
|
|
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 OptimizerTG |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2011-10-27 : 17:35:57
|
using an alias makes thing more readable and saferDELETE eFROM 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 departmentCharlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
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 OptimizerTG |
 |
|
|
Transact Charlie
Master Smack Fu Yak Hacker
3451 Posts |
Posted - 2011-10-27 : 20:19:09
|
| you have to commitCharlie===============================================================Msg 3903, Level 16, State 1, Line 1736The ROLLBACK TRANSACTION request has no corresponding BEGIN TRANSACTION |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
|