Custom Search

Tuesday, 17 January 2012

SQL Drop, Update & Delete statement with Syntax & Example


SQL Drop, Update & Delete statement with Syntax & Example 


The Syntax of a SQL DELETE statement is:
DELETE FROM table_name [WHERE condition];
table_name -- the table name which has to be updated.


Example: 
To delete an employee with id 100 from the employee table, the sql delete
query would be like,
DELETE FROM employee WHERE id = 100;
To delete all the rows from the employee table, the query would be like,
DELETE FROM employee;




The Syntax of a SQL UPDATE statement is


UPDATE table_name
SET column_name1 = value1,
column_name2 = value2, ...
[WHERE condition]


Description
table_name - the table name which has to be updated.
column_name1, column_name2.. - the columns that gets changed.
value1, value2... - are the new values.


Example: 
To update the location of an employee, the sql update query would be
like,
UPDATE employee
SET location ='Mysore'
WHERE id = 101;



Syntax to drop a sql table structure:
DROP TABLE table_name;


Example: 
To drop the table employee, the query would be like
DROP TABLE employee;


No comments:

Post a Comment

Laptops