You are on page 1of 2

----> Creating Tables in SQlSever

Syntax:-
CREATE TABLE <TableName>
(
Column1 [DataType],
Column2 [DataType],
Column3 [DataType],
Column4 [DataType],
Column5 [DataType],
.
.
.
.
ColumnN [DataType]
)

Rules for Creating Tables in SQlSever:-


* Table Must start with an Alphabet [A-Z]
* Tables Name must be unique (No Two tables in DB can have same name)
* Table Name should not contain spaces and special charaters.
But it will allow 3 special characters '$','_','#'
* A Table Name should not exceed 128 Characters lenght
* A Table can have upto 1024 Columns.

Eg:- 123EMP -----> Invalid Table Name (As it started with


numbers)
Emp*123 -----> Invalid Table Name (As it contains Special
character '*')
Emp_123 -----> Valid Table Name

--->Table creation sample scripts :-


CREATE TABLE TblLocation
(
LocationID TINYINT,
LocationName VARCHAR(100),
)

CREATE TABLE TblDepartment


(
DeptID TINYINT,
DeptName VARCHAR(100)
)

CREATE TABLE TblEmployee


(
EmpID SMALLINT,
Empname VARCHAR(100),
DOJ DATE,
Deptid INT,
LocationID TinyInt,
Designation VARCHAR(100)
)

Inserting Values in Tables :-


INSERT INTO TblLocation VALUES ('1','Hyderabad'),
('2','Mumbai'),
('3','Bangalore')
INSERT INTO TblDepartment VALUES ('1','Development'),
('2','Support'),
('3','HRDepartment'),
('4','Finance'),

('5','SupportingStaff')

INSERT INTO TblEmployee VALUES ('1','Sadeep','2019-08-


01','1','1','Teamlead'),
('2','JAYASree','2019-
08-01','1','1','SoftwareEngineer'),
('3','Raju','2019-08-
01','2','3','Technical Associate'),
('4','Ramarao','2019-08-
01','2','3','Senior Associate'),

('5','Chandrasekhar','2019-08-01','1','1','SeniorConsultant'),
('6','xyx','2019-08-
01','3','1','Technical Associate'),
('7','abc','2019-08-
01','1','1','Technical Associate'),
('8','dfdfdf','2019-08-
01','4','1','Teamlead'),

('9','Sadfdfdfeep','2019-08-01','5','1','Technical Associate'),
('10','dfdfdfdf','2019-
08-01','5','1','Technical Associate')

You might also like