Sunday, 10 February 2013

SQL CREATE TABLE Statement Syntax and Example

SQL 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,
....
)

The data type specifies what type of data the column can hold. 


Example:

Now we want to create a table called "EMP" that contains five columns: Emp_ID, E_Name, Job, Dept_ID, and Salary.
We use the following CREATE TABLE statement:

CREATE TABLE [dbo].[EMP](
[Emp_ID] [float] NULL,
[E_Name] [varchar](255) NULL,
[Job] [varchar](255) NULL,
[Dept_ID] [float] NULL,
[Salary] [float] NULL


GO

The columns of Data type 'Float' will hold the Numbers and the columns of Data Type 'Varchar' will hold the Text.


As all the columns have the NULL Constraint , we can enter null values also into the Table.

Thanks,
TAMATAM


No comments:

Post a Comment

Follow Me by Email

ExcelKingdom-Popular Posts

ExcelKingdom-Random Posts