DBMS SQL DAY 12

DAY 12

1.      DML: Data Manipulation Language

DML commands are not auto-committed. It means changes are not permanent to database, they can be rolled back.

Command
Description
1. Insert
to insert a new row
2. Update
to update existing row
3. Delete
to delete a row
4. Merge
merging two rows or two tables

Data Manipulation Language (DML) statements are used for managing data in database. DML commands are not auto-committed. It means changes made by DML command are not permanent to database, it can be rolled back.

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,..)

Let’s see an example,

Consider a table Student with following fields.
S_id
S_Name
age

INSERT into Student values(101,'Adam',15);
The above command will insert a record into Student table.
 S_id

S_Name

age
101
Adam
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,'Alex');

Or,

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

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

S_id

S_Name

age
101
Adam
15
102
Alex


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
Adam
15
102
Alex
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
Adam
15
102
Alex
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
Adam
15
102
Alex
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
Adam
15
102
Alex
18

No comments:

Post a Comment

Give your valuable feedback

Topic :Software & Types, Subject: Computer Fundamental Notes for CSJM University Kanpur(for different courses like BBA, BCA, etc..)

Software Software refers to the programs, data, and instructions that enable a computer or other digital device to perform specific tasks or...