All DML Statement in SQL, Select Statement, Delete, Insert and Update Statement

Data Manipulation Language – DML Statements

Data Manipulation Language (DML) statements get to and control information in existing diagram objects. These queries don’t verifiably confer the present exchange. The information control dialect statements are:


Select Statement

The SELECT statement is a constrained type of DML articulation in that it can just get to information in the database. It can’t control information in the database, in spite of the fact that it can work on the information prior to giving back the results of the query.

Syntax

select * from tbl_name where <condition> order by <sort>

Example

Select * from USERS where ID = 1

 

ID            |              Name                    |              UName                                |              PWord                  |              Status   |

1              |              Tom Brown         |              t.brown                                |              myPass                 |              1              |

Insert Statement:

Insert statement is used to insert data into a table.

Syntax

Insert into tbl_name values (val1, val2, val3,…, val_n)

Example

 

Insert into users values (3, ‘Tim Robbins’, ‘t.robbins’, ‘password’, 1

The above command will insert a record into Users table.

 

ID            |              Name                    |              UName                                |              PWord                  |              Status   |

3              |              Tim Robbins       |              t.robbins              |              P@ssW0rd          |              1              |

Example to Insert NULL value to a column

Both the statements below will insert NULL value into PWord column of the Users table.

insert into USERS(id,Name,UName,Status) values(3,’Tim Robbins’,’t.robbins’,1);


Or,

insert into USERS values(4,’Jack’,’jack’, Null,1);

 

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

ID            |              Name                    |              UName                                |              PWord                  |              Status   |

3              |              Tim Robbins       |              t.robbins              |                                              |              1              |

4              |              Jack                        |              jack                        |                                              |              1              |

Update Statement

Update command is used to update a row of a table.

Syntax

Update tbl_name set col_name = value where condition;

Example

update users set PWord=’password’ where id=3;

 

ID            |              Name                    |              UName                                |              PWord                  |              Status   |

3              |              Tim Robbins       |              t.robbins              |                 password         |              1              |

Delete Statement

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

Syntax

delete from tbl_name;

Example

Delete from users;

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

Example to delete a particular Record from a Table

Consider the following Users table

ID            |              Name                    |              UName                                |              PWord                  |              Status   |

3              |              Tim Robbins       |              t.robbins              |                                              |              1              |

4              |              Jack                        |              jack                        |                                              |              1              |

 delete from users where id=3;

The above command will delete the record where id is 3 from Users table.

ID            |              Name                    |              UName                                |              PWord                  |              Status   |

4              |              Jack                        |              jack                        |                                              |              1              |

More Related Articles For You

    DBMS Tutorial

    SQL and DBMS Interview Questions with Answers

    DBMS and SQL Practice Tests , Questions and Quizzes