Task 4
Task 4
🞂 Learn commands that make changes in relational database and transaction management.
🞂 Gains the knowledge to perform transactions like updating, deleting, inserting and selecting
data from a database.
Software Tools:
Insert Command: this is used to add one or more rows to a table. The values are separated by
commas and the data types char and date are enclosed in apostrophes. The values must be
entered in the same order as they are defined.
Select Commands: It is used to retrieve information from the table. It is generally referred to
as querying the table. We can either display all columns in a table or only specify column from
the table.
Update Command: It is used to alter the column values in a table. A single column may be
updated or more than one column could be updated.
Delete command: After inserting row in a table we can also delete them if required. The delete
command consists of a ‘from’ clause followed by an optional ‘where’ clause.
1.INSERT INTO: This is used to add records into a relation. These are three type
of INSERT INTO queries which are as
a)Inserting a single record
Syntax: INSERT INTO < relation/table name> (field_1,field_2……
field_n)VALUES (data_1,data_2,. data_n);
Example: SQL>INSERT INTO student(sno,sname,class,address)VALUES
(1,’Ravi’,’M.Tech’,’Palakol’);
b)Inserting a single record
Syntax: INSERT INTO < relation/table name>VALUES (data_1,data_2,.......data_n);
Example: SQL>INSERT INTO student VALUES (1,’Ravi’,’M.Tech’,’Palakol’);
c)Inserting all records from another relation
Syntax: INSERT INTO relation_name_1 SELECT Field_1,field_2,field_n
FROM relation_name_2 WHERE field_x=data;
Example: SQL>INSERT INTO std SELECT sno,sname FROM
student WHERE name = ‘Ramu‘;
d)Inserting multiple records
Syntax: INSERT INTO relation_name field_1,field_2,......field_n) VALUES
(&data_1,&data_2,.. . .&data_n);
Example: SQL>INSERT INTO student (sno, sname, class,address)
VALUES (&sno,’&sname’,’&class’,’&address’);
Enter value for sno: 101
Enter value for name: Ravi
Enter value for class: M.Tech
Enter value for name: Palakol
3.DELETE-FROM: This is used to delete all the records of a relation but it will retain the
structure of that relation.
a)DELETE-FROM: This is used to delete all the records of relation.
Syntax: SQL>DELETE FROM relation_name;
Example: SQL>DELETE FROM std;
b)DELETE -FROM-WHERE: This is used to delete a selected record from a relation.
Syntax: SQL>DELETE FROM relation_name WHERE condition;
Example: SQL>DELETE FROM student WHERE sno = 2;
4.TRUNCATE: This command will remove the data permanently. But structure will not be
removed.
Difference between Truncate & Delete:-
by using truncate command data will be removed permanently & will not get back where as
by using delete command data will be removed temporally & get back by using roll back
command.
by using delete command data will be removed based on the condition whereas by using
truncate command there is no condition.
Truncate is a DDL command & delete is a DML command.
10 ACCOUNTING
20 RESEARCH
30 SALES
3.SELECT - FROM -WHERE: This query is used to display a selected set of fields
for a selected set of records of a relation.
Syntax: SELECT a set of fields FROM relation_name WHERE condition;
Example: select * FROM dept WHERE deptno<=20;
DEPTNO DNAME LOC
BOOKS
BookID Title Author Publisher Price StockQuantity
1 The Great Gatsby F. Scott Scribner 10.99 48
Fitzgerald
2 To Kill a Harper Lee J.B. Lippincott & 21.45 100
Mockingbird Co.
3 1984 George Orwell Secker & Warburg 15.99 150
4 Moby Dick Herman Melville Harper & Brothers 25.90 120
5 Pride and Prejudice Jane Austen T. Egerton 9.99 80
Orders
OrderID OrderDate CustomerID TotalAmount
1 2024-10-08 1 21.98
2 2024-10-09 3 35.67
Order_Details
OrderDetailID OrderID BookID Quantity Subtotal
1 1 1 2 21.98
2 2 2 1 11.20
2 2 4 1 24.47