Wednesday 1 May 2013

DML - Data Manipulation Language

DML-Data Manipulation Language
Select,Insert,Delete,Update

Select statement
The SELECT statement is used to select data from a database.
The result is stored in a result table, called the result-set.
Syntax:
SELECT column_name(s)
FROM table_name
and
SELECT * FROM table_name
select * from employee
select * from employee where salary > 20000
select * from employee where salary between 15000 and 35000

Insert statement

The INSERT INTO statement is used to insert a new row or record in a table.
Syntax:
It is possible to write the INSERT INTO statement in two forms.
The first form doesnt specify the column names where the data will be inserted,
only their values:
INSERT INTO table_name
VALUES (value1, value2, value3,...)

The second form specifies both the column names and the values to be inserted:
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)

insert into employee values(1,'siva','pgr',40000.00,10)
insert into employee values(2,'sakthi','pld',50000.00,20)
insert into employee values(3,'Imrankhan','tml',60000.00,30)
insert into employee values(4,'sachin','pgr',70000.00,40)
insert into employee values(5,'Ranbhir','pgr',40000.00,50)

insert into employee(empno,name,desg) values(6,'Dhoni','kep')
'INSERT'
CREATE TABLE Persons1
(
P_Id int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)
INSERT INTO Persons
VALUES (7,'SIVA', 'SAKTHI', 'VIRUDHACHALAM', 'NEYVELI')
select *from persons
INSERT INTO Persons (P_Id, LastName, FirstName)
VALUES (5, 'Tjessem', 'Jakob')
INSERT INTO Persons (P_Id, LastName)
VALUES (5, 'Tjessem')


Delete statemet

The DELETE statement is used to delete rows or records in a table.
syntax:
DELETE FROM table_name
WHERE some_column=some_value
delete from employee where empno=6

Note: Notice the WHERE clause in the DELETE syntax.
The WHERE clause specifies which record or records that should be deleted.
If you omit the WHERE clause, all records will be deleted!
Delete All Rows
It is possible to delete all rows in a table without deleting the table.
This means that the table structure, attributes, and indexes will be intact:
DELETE FROM table_name
delete from employee
'DELETE'
DELETE FROM table_name
delete from persons1
DELETE FROM Persons
WHERE LastName='Tjessem' AND FirstName='Jakob'


Update statement

The UPDATE statement is used to update existing records in a table.
Syntax:
UPDATE table_name
SET column1=value, column2=value2,...
WHERE some_column=some_value
Note: Notice the WHERE clause in the UPDATE syntax.
The WHERE clause specifies which record or records that should be updated.
If you omit the WHERE clause, all records will be updated!

update employee set salary = salary+5000 where empno = 4
UPDATE
UPDATE Persons
SET Address='Nissestien 67', City='Sandnes'
WHERE LastName='Tjessem' AND FirstName='Jakob'


0 comments:

Post a Comment