Sql Statement

DML command

SQL is equipped with data manipulation language. DML modifies the database instance by inserting, updating and deleting its data. DML is responsible for all data modification in databases. SQL contains the following set of command in DML section:

  • SELECT/FROM/WHERE

  • INSERT INTO/VALUES

  • UPDATE/SET/WHERE

  • DELETE FROM/WHERE


1) INSERT command

Insert command is used to insert data into a table. Following is its general syntax

INSERT into table-name values(data1,data2,..)

Lets see an example

Consider a table Student with following fields.

for more details click on more button

S_id S_Name age
INSERT into Student values(101,'John',15);

The above command will insert a record into Student table.

S_id S_Name age
101 John 15

Example to Insert NULL value to a column

Both the statements below will insert NULL value into age column of the Student table.

INSERT into Student(id,name) values(102,'Alam');

Or,

INSERT into Student values(102,'Alam',null);

The above command will insert only two column value other column is set to null.

S_id S_Name age
101 John 15
102 Alam

Example to Insert Default value to a column

INSERT into Student values(103,'Chris',default)
S_id S_Name age
101 John 15
102 Alam
103 chris 14

Suppose the age column of student table has default value of 14.

Also, if you run the below query, it will insert default value into the age column, whatever the default value may be.

INSERT into Student values(103,'Chris')

2) UPDATE command

Update command is used to update a row of a table. Following is its general syntax,

UPDATE table-name set column-name = value where condition;

Lets see an example,

update Student set age=18 where s_id=102;
S_id S_Name age
101 John 15
102 Alam 18
103 chris 14

Example to Update multiple columns

UPDATE Student set s_name='Abhi',age=17 where s_id=103; 

The above command will update two columns of a record.

S_id S_Name age
101 John 15
102 Alam 18
103 Abhi 17

3) Delete command

Delete command is used to delete data from a table. Delete command can also be used with condition to delete a particular row. Following is its general syntax,

DELETE from table-name;

Example to Delete all Records from a Table

DELETE from Student;

The above command will delete all the records from Student table.

Example to Delete a particular Record from a Table

Consider the following Student table

S_id S_Name age
101 John 15
102 Alam 18
103 Abhi 17
DELETE from Student where s_id=103;

The above command will delete the record where s_id is 103 from Student table.

S_id S_Name age
101 John 15
102 Alam 18

Admin has written 171 articles

Leave a Reply