SQLSERVER-CLASS4
SQLSERVER-CLASS4
SQLSERVER-CLASS4
Features of SQL:
SQL is not a case sensitive language it means that all the commands of Sql
are not case sensitive
Every command of sql should ends with a semicolon (;) (It is exemption for
SQL Server)
SQL can be pronounced as Sequel (Structured English Query Language)
SQL can be called as Common Language Interface, which is used to
communicate with any type of database
SQL can be called as NLI (Natural Language Interface). It means that all the
SQL Commands are almost similar to normal English language
Structured query language is mainly divided into 4 sub languages
1. DDL (Data Definition Language)
2. DML (Data Manipulation Language)
3. TCL (Transaction Control Language)
4. DCL(Data Control Language)
5. DQL (Data Query Language)
1. Create:
This command is used to create the database objects within the database
Syntax: CREATE TABLE <TABLE NAME>
(COL 1 DATA TYPE (size),
COL2 DATA TYPE (size),
:
:
:
COLN DATA TYPE (size));
Ex: CREATE TABLE EMP (EID Int, ENAME Varchar (15), SAL
DECIMAL (6, 2));
2. ALTER:
This command is used to modify the structure of a table using this
command, we can perform four different operations
Using this command we can increase (or) decrease the size of the data
type & also we can change the data type from old data type to new
data type
We can add a new column to the existing table
We can change the column name from old column name to new
column name
We can remove the column from the existing table
This command contains 4 sub commands
1. ALTER- ALTER COLUMN
2. ALTER- ADD
3. SP_RENAME
4. ALTER- DROP
a. ALTER-ALTER COLUMN:
b. ALTER-ADD:
c. ALTER-DROP:
d. SP_RENAME:
Syntax: SP_RENAME ‘TABLENAME.OLDCOLUMN’,’NEW COLUMN
NAME’,’COLUMN,;
Ex: SP_RENAME ‘EMP.SAL’,’SALARY’,’COLUMN’
3. SP_RENAME:
This command is used to change the table name from old table name to new
table name
Syntax: SP_Rename ‘old table name’,’ New table name’
Ex: SP_Rename ‘EMP’,’EMP1’
4. TRUNCATE:
This command is used for to delete all the records from existing table
permanently
Syntax: TRUNCATE TABLE <TABLE NAME>
Ex: TRUNCATE TABLE EMP;
5. DROP:
This command is used to remove the table permanently from the database
Syntax: DROP TABLE <TABLE NAME>
Ex: DROP TABLE EMP;
1. INSERT:
Using this command we can Insert the records into the existing table
We can insert the records into the table in two methods
Explicit method
Implicit method
Explicit method:
In this method user has to enter all the values into all the columns without
anything omitting (or) left any column data
Syntax: INSERT INTO <TABLE NAME> VALUES <VAL1, VAL2,
….VALN>;
(OR)
INSERT <TABLE NAME> VALUES <VAL1, VAL2, .VALN>;
(Here “INTO” Keyword is optional)
Implicit method:
In this method we can enter the values into the required columns in the table,
so that user can omit (or) left some columns data while he enters the records
into the table
If the user omit any column data in the table then it automatically takes
NULL
Syntax: INSERT INTO <TABLE NAME> (COL1, COL2….COLN)
VALUES (VAL1, VAL2… VALN);
Ex: INSERT INTO EMP (EID, SAL) VALUES (106,9999);
2. UPDATE:
3. DELETE:
06 Truncate will reset the identity Delete will not reset the identity
Values value
1. SELECT:
WHERE CLAUSE:
This clause is used to check the condition based on the condition, we can
retrieve, update, delete specific records in the table
So we can apply the where clause only in select, update & delete
ALIAS:
ALIAS is a duplicate name (or) alternate name for the original column name
(or) Table name (or) an expression name.