Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

Government College of Engineering, Nagpur

Department of Computer Science & Engineering


Practical LAB Manual Solutions (2021-22)
IV th Semester

Subject:
DATABASE MANAGEMENT SYSTEM

Branch : CSE { DIRECT SECOND YEAR }


Name: Vishal Suresh Kesharwani Enrolment No./Rollno. 74
Batch: B4. Subject Teacher: Prof. Priya Khotele

PRACTICAL NO.04

AIM:-- To apply TRUNCATE AND DELETE command on attributes of Table values.

THEORY:--
SQL COMMANDS
SQL commands are instructions. It is used to communicate with the database. It is also
used to perform specific tasks, functions, and queries of data.
SQL can perform various tasks like create a table, add data to tables, drop the table,
modify the table, set permission for users.
Types of SQL Commands
There are five types of SQL commands: DDL, DML, DCL, TCL, and DQL.

TRUNCATE TABLE

The TRUNCATE TABLE command deletes the data inside a table, but not the table
itself.
The following SQL truncates the table "Categories":

Example

TRUNCATE TABLE Categories;

The SQL DELETE Statement

The DELETE statement is used to delete existing records in a table.

DELETE Syntax

DELETE FROM table_name WHERE condition;

Note: Be careful when deleting records in a table! Notice the WHERE clause in the
DELETE statement. The WHERE clause specifies which record(s) should be deleted. If
you omit the WHERE clause, all records in the table will be deleted!

Demo Database

Below is a selection from the "Customers" table in the Northwind sample database:

SQL DELETE Example

The following SQL statement deletes the customer "Alfreds Futterkiste" from the
"Customers" table:

Example

DELETE FROM Customers WHERE CustomerName='Alfreds Futterkiste';

Delete All Records

It is possible to delete all rows in a table without deleting the table. This means that
the table structure, attributes, and indexes will be intact:

DELETE FROM table_name;

The following SQL statement deletes all rows in the "Customers" table, without
deleting the table:

Example

DELETE FROM Customers;

PROGRAM CODE:--
SQL> create database DBMS ;
SQL> use DBMS;
SQL> create table employee (
emp_id int,
emp_name varchar(40),
salary int ,
city varchar (40)
);
mysql> insert into newemployee values(1,'vishal',1000,'gondia','v@gmail');
Query OK, 1 row affected (0.71 sec)

mysql> insert into newemployee values(2,'vikash',3000,'gondia','vv@gmail');


Query OK, 1 row affected (0.60 sec)

mysql> insert into newemployee values(3,'priyansh',1000,'nagpur','cc@gmail');


Query OK, 1 row affected (0.51 sec)

mysql> insert into newemployee values(4,'dj',5000,'nagpur','dd@gmail');


Query OK, 1 row affected (0.42 sec)

mysql> DELETE FROM newemployee WHERE emp_id=6;


DELETE FROM newemployee WHERE salary=1000;
TRUNCATE TABLE newemployee;

OUTPUT:
RESULT : The Practial to implement UPDATE command on attributes of table values performed
successfully.

You might also like