SQL Server Create Table Query

A table is a database object used to store data and table is combination of rows and columns. Each row in a table denotes a unique record and each column denotes an attribute of the record.

Column names within a table must be unique but same column name can be used in different tables within a database.

How to create table in SQL Server ?

CREATE TABLE Statement is used to create a table in the database.

CREATE TABLE Syntax

CREATE TABLE table_name 
(
column_name datatype [NULL | NOT NULL]
[IDENTITY (SEED, INCREMENT)],
column_name datatype ....
)

NULL | NOT NULL are keywords that specify whether or not NULL values are allowed.

IDENTITY is used for those columns that need automatically generated unique system values and can be used to generate sequential numbers.

SEED is the starting or the initial value for the IDENTITY column.

INCREMENT is the step value used to generate the next value for the column. This value can also be negative.

CREATE TABLE Example

CREATE TABLE Department
(
Id int NOT NULL,
Name varchar(25) NOT NULL,
Head varchar(25)
)
Output:
Command(s) completed successfully.

CREATE TABLE WITH IDENTITY FIELD

CREATE TABLE Employee
(
Id int IDENTITY(1,1),
Name varchar(25) NOT NULL,
DeptId int NOT NULL,
Email varchar(25) NULL
)
Output:
Command(s) completed successfully.
CREATE TABLE Employee
(
Id int IDENTITY(1,1),
Name varchar(25) NOT NULL,
DeptId int NULL,
Email varchar(25) NULL,
Salary int NOT NULL,
City varchar(20),
Country varchar(20)
)
Command(s) completed successfully.

How to remove the table in database ?

DROP Statement is used to remove the table in the database.

DROP TABLE Statement

DROP TABLE <TABLE NAME>

DROP TABLE Example

Empployee table has been removed in the current database.
DROP TABLE Employee



Python installation

Privacy Policy  |  Copyrightcopyright symbol2020 - All Rights Reserved.  |  Contact us   |  Report website issues in Github   |  Facebook page   |  Google+ page

Email Facebook Google LinkedIn Twitter
^