Data Manipulation Language(DML)

A DML statement can be used as whenever you want to

DML is a very important part of Structure Query Language(SQL). Whenever you want to add, modify, delete data in a database you execute a DML statement. A collection of DML statement is called as a transaction. 

Entering records into a table:

The insert statement helps us to insert a record in a table. The syntax of insert statement is :

Insert into table name( column,column1,column2,..)
Values(value,valu1,valu2,.);
Where table name is the name of the table.
Column, column1..is the names of columns in the table.
Value,value1,value2,..is the corresponding values for the columns.

Note

Entering records with null values:

Implicit method:- removing the column from the column list whose value will be null. For example,

insert into department(dept-id, name)
values(12, 'marketing');
Here a new record will be added to the department table where the value of dept-id and name will be 12, marketing respectively and the other field values will be null.

Explicit method:-

specifying the null keyword or a single space enclosed between two single quotes(‘ ‘) in the values clause. For example:

insert into department
values(12, 'marketing', null, null);

Note:

If you want to put null in a character or date type field in that case specify a single space enclosed by quotes(' ') in the values list.

Changing data in a table using update statements:

The update statement can be used to make changes on the existing records of a table. The update statement can update more than one record at a time. The syntax of update statement is:

Update table
set column=value[, column=value,]
[where condition]
where table is the name of table.

Column is the name of column in the table which has to be filled with a new value. Value is a corresponding value for the column.
Condition identifies the row to be updated.

Example;
update emp
set dept-id=20
where emp-id=102;

In the above example the dept-id of the employee whose emp-id is 102. The where clause is used in SQL statement whenever you have to do an operation based on a condition.

Note

If you want to make changes on a field of a table which is dependant to some other table then ensure that new value is valid one in the other table. Otherwise integrity constraint error will come.

Removing a row from a table :

The delete statement is used to remove a row from a table. The syntax of delete statement is :

delete from table
where condition ;

Note :

If no rows are deleted, a message "0 rows deleted" is returned. For example,

delete from departments
where dept_name='marketing';
1row deleted.


  Tutorials

Popular Links

Contact Us

address Plot No-741,2ND Floor
Opp. Bhagabati Temple,Jayadev Vihar
      Bhubaneswar-751013
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved