May 06, 2009

SQL Basic Syntax

Create Statement
It is used to create a new database.
CREATE DATABASE database_name
It is used to create a new table.
CREATE TABLE table_name (column_name1 data_type1 NULL|NOT NULL, column_name2 data_type2 NULL|NOT NULL)
It is used to create a new column in a table.
ALTER TABLE table_name
ADD column_name data_type NULL|NOT NULL

Drop Statement
It is used to delete an existing database.
DROP DATABASE database_name
It is used to delete an existing table.
DROP TABLE table_name
It is used to delete an existing column in a table.
ALTER TABLE table_name
DROP COLUMN column_name

Rename Statement
It is used to rename an existing table.
sp_rename existing_table_name, new_table_name
It is used to rename an existing column.
sp_rename existing_column_name, new_column_name, 'COLUMN'

Insert Statement
It is used to insert a new row of data to a table.
INSERT INTO table_name (column_name1, column_name2)
VALUES (value1, value2)
It allows to insert multiple rows into a table. You can retrieve the data from another table and insert it into a new table.
INSERT INTO table_name1 (column_name1, column_name2)
SELECT column_name3, column_name4 FROM table_name2

Update Statement
It is used to update an existing record in a table.
UPDATE table_name
SET column_name1 = value1, column_name2 = value2
WHERE expression

Delete Statement
It is used to delete rows in a table.
DELETE FROM table_name
WHERE expression

0 comments:


Post a Comment