SQL Server DELETE Statement
The delete statement is used to delete the existing records
DELETE FROM table_name
WHERE [condition];
NOTE: WHERE clause from the syntax must be noticed or else entire data gets deleted
Consider the CUSTOMERS table having the following records
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ranith | 32 | Ahmedabad | 2000.00 |
| 2 | Krupa | 25 | Delhi | 1500.00 |
| 3 | kaulik | 23 | Kota | 2000.00 |
| 4 | Chaitan | 25 | Mumbai | 6500.00 |
| 5 | Munny | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
The following code has a query, which will DELETE a customer, whose ID is 2.
SQL> DELETE FROM CUSTOMERS
WHERE ID = 2;
Now, the CUSTOMERS table would have the following records
+----+----------+-----+-----------+----------+
| ID | NAME | AGE | ADDRESS | SALARY |
+----+----------+-----+-----------+----------+
| 1 | Ranith | 32 | Ahmedabad | 2000.00 |
| 3 | kaulik | 23 | Kota | 2000.00 |
| 4 | Chaitan | 25 | Mumbai | 6500.00 |
| 5 | Munny | 24 | Indore | 10000.00 |
+----+----------+-----+-----------+----------+
If you want to DELETE all the records from the CUSTOMERS table, you do not need to use the WHERE clause
SQL> DELETE FROM CUSTOMERS;
Now, the CUSTOMERS table will not have any record
SQL Server Connection String Formats
posted on 2019-08-27 05:53:53 - SQL Server Tutorials