0% found this document useful (0 votes)
20 views5 pages

Insert Into Values: Constraint, Value2 Datatype Constraint, Value3 Datatype Constraint, ... )

The document discusses using DML commands like INSERT, UPDATE, DELETE in MySQL. It describes creating a table called "employee" with attributes like ID, name, salary etc. and then demonstrates inserting sample records. Various UPDATE queries are shown to modify records based on conditions. DELETE queries remove records that meet certain criteria like salary less than a value. The objective is to get familiar with common DML commands through hands-on practice in a lab.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
0% found this document useful (0 votes)
20 views5 pages

Insert Into Values: Constraint, Value2 Datatype Constraint, Value3 Datatype Constraint, ... )

The document discusses using DML commands like INSERT, UPDATE, DELETE in MySQL. It describes creating a table called "employee" with attributes like ID, name, salary etc. and then demonstrates inserting sample records. Various UPDATE queries are shown to modify records based on conditions. DELETE queries remove records that meet certain criteria like salary less than a value. The objective is to get familiar with common DML commands through hands-on practice in a lab.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1/ 5

LAB 4 FAMILIARIZATION WITH DML COMMANDS.

(INSERT, UPDATE,
DELETE) AND DCL COMMANDS. (GRANT, REVOKE) (CREATION OF
USER,CREATION OF SESSION AND PRIVILEGE)

OBJECTIVE:
 To get familiarize with DML commands in mysql
THEORY:
DML is short name of Data Manipulation Language which deals with data manipulation and
includes most common SQL statements such SELECT, INSERT, UPDATE, DELETE, etc.,
and it is used to store, modify, retrieve, delete and update data in a database.
 SELECT - retrieve data from a database
 INSERT - insert data into a table
 UPDATE - updates existing data within a table
 DELETE - Delete all records from a database table
 MERGE - UPSERT operation (insert or update)
 CALL - call a PL/SQL or Java subprogram
 EXPLAIN PLAN - interpretation of the data access path
 LOCK TABLE - concurrency Control
Some of the syntax of common dml commands are :
INSERT
INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1 datatype
constraint, value2 datatype constraint, value3 datatype constraint, ...);
UPDATE
UPDATE table_name SET column1 = value1, column2 = value2, ...
WHERE condition;
DELETE
DELETE FROM table_name WHERE condition;

DCL:
DCL is short name of Data Control Language which includes commands such as GRANT
and mostly concerned with rights, permissions and other controls of the database system.

 GRANT - allow users access privileges to the database


 REVOKE - withdraw users access privileges given by using the GRANT command

WORK:
QUESTION
1. Create a employee table with attributes id (Primary key), name, gender salary
(>20000), address, mobile (unique)
Ans-> CREATE TABLE employee (id int PRIMARY KEY AUTO_INCREMENT,
name varchar (30), gender varchar (10), salary bigint CHECK (salary>20000),
address varchar (30), mobile bigint UNIQUE);

2. Use insert command to insert 10 new records


Ans-> INSERT INTO `employee`
VALUES(1,'Radhe','male',31212,'Chapagaoun',988412314),
(2,'Ishwor','male',303230,'Manthali',9841230454),
(3,'Binod','male',40011,'Pokhara',9841238880),
(4,'Annanda','male',512120,'Peutar',9844232314),
(5,'Soiya','female',255413,'Ramechhap',9833302314),
(6,'Ranta','female',31210,'Patan',9841232111);

3. Update the salary of the employee whose name Ram


Ans-> UPDATE `employee` SET `salary`= 70000 WHERE name=’Binod’;

4. Update the address of the employee who are from ktm and pkr to bkt
Ans-> UPDATE `employee` SET `address`='Humla' WHERE address='Peutar' OR
address= 'Pokhara';

5. Update gender of the employee whose name is kamal to m.


Ans-> UPDATE `employee` SET `gender`='male' WHERE name='Ratna';

6. Update the address to pkr whose address is ktm


Ans-> UPDATE employee SET address= 'Panauti' WHERE address='Patan';

7. Increase salary of every employee by 10%.


Ans-> UPDATE employee SET salary=salary+salary*0.1;
8. Delete the record of the employee whose salary is less than 10000
Ans-> DELETE FROM `employee` WHERE salary< 100000;

9. Delete the record of employee whose name start from s


Ans-> DELETE FROM employee WHERE name LIKE 's%';

10. Delete the record of the employee who’s mobile is 111.


Ans-> DELETE FROM employee WHERE mobile=9844232314;
CONCLUSION:
Here we use various dml commands and use it in my sql. We get familirse with these
commands by doing this lab.

You might also like