Friday, 2 September 2016

Sql Server Data Manipulation Language(DML) and Data Definition Language(DDL)

Data Manipulation Language (DML)
It is used to insert, delete, modify and retrieve data in database.
example : select, update, insert , delete statement

Select Statement
It is used to retrieve one or more rows from the table in database.
example 1: return all the rows from the table
select * from employeeMaster



example 2: return particular rows from table
select * from employeeMaster where Salary>35000


Insert statement
It is used to insert one or more rows in the table.
example 1 : Inserting single row
insert into employeeMaster (EmpName,DesignationId,LocationId,Salary)

Values('Tanuj', 3,3 ,67000)

select * from employeeMaster where EmpName='Tanuj'


example 2 : Inserting multiple rows
insert into employeeMaster (EmpName,DesignationId,LocationId,Salary)

Values('Swapnil', 3,3 ,57000),('Rahul',1,1,45000)

select * from employeeMaster where EmpName in ('Swapnil','Rahul')


Update Statement
It is used to update data of the table
example 1: update employeeMaster set Salary=50000 where EmpName in ('Swapnil','Rahul')

select * from employeeMaster where EmpName in ('Swapnil','Rahul')



Delete Statement
It is used to delete one or more rows from the table in database.

delete from employeeMaster where EmpName in ('Swapnil','Rahul')

select * from employeeMaster where EmpName in ('Swapnil','Rahul')
No rows will be returned

Data Definition Language
It is used to create, modify and remove the structure of database objects.
Example : Create, Alter and Drop statement

Create statement 
It is used to create the structure of table, function, procedures, user defined table type etc.

Create table test
(
testid int,
testName varchar(50)

)

to see the structure :sp_help test


Alter Statement
It is used to alter the structure of table, function, procedures etc.
example:
alter table test add testDate datetime
to see the structure :sp_help test

drop column: alter table test drop column testDate

Modify column: alter table test alter column testname varchar(100)

Drop Statement
It is used to drop the structure and data.
example : drop table test






0 comments:

Post a Comment