You are on page 1of 6

Practical No.

4: INSERT AND DELETE RECORDS IN TABLE

Name: Harsh Tiwari


ENROLMENT NO. 2001160392
ROLL NO. 32

RESOURCES USED:

SR NO. NAME OF RESOURCE SPECIFICATIONS


1. HP OMEN laptop Computer system to
8GB RAM, 1TB STORAGE install the software
2. Google Chrome
3. MySql

RESULTS:
We completed this practical successfully and inserted and deleted the
data easily without any errors.

CONCLUSION:
Now we are able to insert and delete the records in a table in the
MySql software.

PRACTICAL RELATED QUESTIONS:


1. State the difference between Delete and Truncate.

Comparison DELETE TRUNCATE


Basis

Definition The delete statement is used to remove The truncate command removes the complete
single or multiple records from an existing data from an existing table but not the table
table depending on the specified itself. It preserves the table structure or schema.
condition.

Language It is a DML (Data Manipulation Language) It is a DDL (Data Definition Language) command.
command.

WHERE It can use the WHERE clause to filter any It does not use the WHERE clause to filter
specific row or data from the table. records from the table.

Permission We need to have DELETE permission to We need to have ALTER permission to use this
use this command. command.

Working This command eliminates records one by This command deletes the entire data page
one. containing the records.

Table Identity This command does not reset the table It always resets the table identity.
identity because it only deletes the data.

Transaction It maintains transaction logs for each It does not maintain transaction logs for each
deleted record. deleted data page.

Speed Its speed is slow because it maintained the Its execution is fast because it deleted entire
log. data at a time without maintaining transaction
logs.

Trigger This command can also activate the This command does not activate the triggers
trigger applied on the table and causes applied on the table to fire.
them to fire.

Space The DELETE statement occupies more The TRUNCATE statement occupies less
transaction space than truncate because it transaction space because it maintains a
maintains a log for each deleted row. transaction log for the entire data page instead
of each row.

2. Write the syntax for methods used to insert data in table.


(I) INSERT INTO table_name ( field1, field2,...fieldN )    
VALUES    
( value1, value2,...valueN );   
 
(II) INSERT INTO table_name VALUES  
( value1, value2,...valueN )  
( value1, value2,...valueN )  
...........  
( value1, value2,...valueN );    
3. Exercise: Attempt following questions:
1. Create one table and insert 10 records in it.
CREATE TABLE `student`.`student` (
`student_id` INT NOT NULL,
`name` VARCHAR(45) NOT NULL,
`address` VARCHAR(45) NOT NULL,
`email_id` VARCHAR(45) NOT NULL,
PRIMARY KEY (`student_id`));
INSERT INTO `student`.`student` (`student_id`, `name`, `address`, `email_id`) VALUES ('1', 'rohit', 'asdf',
'rohit@gmail.com');
INSERT INTO `student`.`student` (`student_id`, `name`, `address`, `email_id`) VALUES ('2', 'rohan', 'dfgh',
'rohan@gmail.com');
INSERT INTO `student`.`student` (`student_id`, `name`, `address`, `email_id`) VALUES ('3', 'rohini', 'ghjk',
'rohini@gmail.com');
INSERT INTO `student`.`student` (`student_id`, `name`, `address`, `email_id`) VALUES ('4', 'rohidas',
'fghj', 'rohidas@gmail.com');
INSERT INTO `student`.`student` (`student_id`, `name`, `address`, `email_id`) VALUES ('5', 'ronit', 'rtyu',
'ronit@gmail.com');
INSERT INTO `student`.`student` (`student_id`, `name`, `address`, `email_id`) VALUES ('6', 'ronika', 'tyui',
'ronika@gmail.com');
INSERT INTO `student`.`student` (`student_id`, `name`, `address`, `email_id`) VALUES ('7', 'ruhana',
'wert', 'ruhana@gmail.com');
INSERT INTO `student`.`student` (`student_id`, `name`, `address`, `email_id`) VALUES ('8', 'rupesh',
'qwer', 'rupesh@gmail.com');
INSERT INTO `student`.`student` (`student_id`, `name`, `address`, `email_id`) VALUES ('9 ', 'rupali', 'yuio',
'rupali@gmail.com');
INSERT INTO `student`.`student` (`student_id`, `name`, `address`, `email_id`) VALUES ('10', 'ruhi', 'cdfr',
'ruhi@gmail.com');
2. Delete the records using delete command.
DELETE FROM `student`.`student` WHERE (`student_id` = '10');

3. Create table for employee whose attributes are emp_id, emp_name, date_of_joining,
Emp_salary, emp_dept and insert 10 rows in it.

CREATE TABLE `employee`.`employee` (


`emp_id` INT NOT NULL,
`emp_name` VARCHAR(45) NOT NULL,
`date_of_joining` INT NOT NULL,
`emp_salary` VARCHAR(45) NOT NULL,
`emp_dept` VARCHAR(45) NOT NULL,
PRIMARY KEY (`emp_id`));

INSERT INTO `employee`.`employee` (`emp_id`, `emp_name`, `date_of_joining`,


`emp_salary`, `emp_dept`) VALUES ('1', 'dipika', '12/3/2000', '10000', 'sales');
INSERT INTO `employee`.`employee` (`emp_id`, `emp_name`, `date_of_joining`,
`emp_salary`, `emp_dept`) VALUES ('2', 'devika', '15/5/2021', '12000', 'marketing');
INSERT INTO `employee`.`employee` (`emp_id`, `emp_name`, `date_of_joining`,
`emp_salary`, `emp_dept`) VALUES ('3', 'dipali', '16/7/2020', '13000', 'it');
INSERT INTO `employee`.`employee` (`emp_id`, `emp_name`, `date_of_joining`,
`emp_salary`, `emp_dept`) VALUES ('4', 'dipakshi', '18/10/2014', '14000', 'hr');
INSERT INTO `employee`.`employee` (`emp_id`, `emp_name`, `date_of_joining`,
`emp_salary`, `emp_dept`) VALUES ('5', 'dipmala', '10/2/2015', '18000', 'sales');
INSERT INTO `employee`.`employee` (`emp_id`, `emp_name`, `date_of_joining`,
`emp_salary`, `emp_dept`) VALUES ('6', 'dipti', '16/7/2015', '17000', 'marketing');
INSERT INTO `employee`.`employee` (`emp_id`, `emp_name`, `date_of_joining`,
`emp_salary`, `emp_dept`) VALUES ('7', 'divya', '14/3/2002', '16000', 'it ');
INSERT INTO `employee`.`employee` (`emp_id`, `emp_name`, `date_of_joining`,
`emp_salary`, `emp_dept`) VALUES ('8', 'diksha', '17/6/2019', '18000', 'hr');
INSERT INTO `employee`.`employee` (`emp_id`, `emp_name`, `date_of_joining`,
`emp_salary`, `emp_dept`) VALUES ('9', 'dipa', '14/2/2009', '19000', 'sales');
INSERT INTO `employee`.`employee` (`emp_id`, `emp_name`, `date_of_joining`,
`emp_salary`, `emp_dept`) VALUES ('10', 'devanshi', '5/5/2005', '20000', 'marketing');

4. Create table for student with related attributes and check the total number of records.
CREATE TABLE `student`.`student` (
`student_id` INT NOT NULL,
`name` VARCHAR(45) NOT NULL,
`address` VARCHAR(45) NOT NULL,
`email_id` VARCHAR(45) NOT NULL,
PRIMARY KEY (`student_id`));

select count(*) as total_record from student.student;

You might also like