Translate

Showing posts with label DDL commands in sql. Show all posts
Showing posts with label DDL commands in sql. Show all posts

Thursday, January 26, 2012

The ALTER TABLE Statement

The ALTER TABLE statement is used to add, delete, or modify columns in an existing table.
Syntax: 
To add-  ALTER TABLE <table_name> ADD <column_name>  datatype
To delete a col-  ALTER TABLE table_name DROP COLUMN column_name
To chng datatyp of col-  ALTER TABLE table_name ALTER COLUMN column_name datatype

The CREATE TABLE Statement

The CREATE TABLE statement is used to create a table in a database.
Syntax:
CREATE TABLE <table_name>
(
<column_name1> <data_type>,
<column_name2> <data_type>,
<column_name3> <data_type>,
....
)
Example:
 Now we want to create a table called "Persons" that contains five columns: P_Id, LastName, FirstName, Address, and City.
Query:
CREATE TABLE Persons
(
P_Id int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)
Output:
The empty "Persons" table will now look like this:

P_Id    LastName    FirstName    Address    City      
                   

The CREATE DATABASE Statement

The CREATE DATABASE statement is used to create a database.
Syntax:           CREATE DATABASE <database_name>
Example:         CREATE DATABASE my_db