PR 45 Dbms
PR 45 Dbms
Date: _________________
Practical No.5: Write SQL queries to use Update, alter, rename, delete, truncate anddistinct.
A. Objective:
SQL commands is to facilitate efficient data management in databases by providing
functionalities such as inserting new data, retrieving specific information, updating
existing records, deleting unnecessary data, and altering table structures.
E. Practical Outcome(PRo)
Students will be able to create and manipulate SQL tables.
G. Prerequisite Theory:
SQL Commands
SQL commands are instructions. It is used to communicate with the
database. Itis 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
thetable, modify the table, set permission for users.
256120316009 page-
Database Management (DI03016041)
DDL changes the structure of the table like creating a table, deleting a table,
altering a table, etc. All the command of DDL are auto-committed that means it
permanently save all the changes in the database. Here are some commands that
come under DDL:
a. CREATE
b. ALTER
c. DROP
d. TRUNCATE
a. CREATE:
It is used to create a new table in the database.
Syntax : CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,....]);
Example : CREATE TABLE EMPLOYEE(Name VARCHAR2(20), Email
VARCHAR2(100), DOB DATE);
b. DROP:
It is used to delete both the structure and record stored in the table.
Syntax : DROP TABLE table_name;
Example : DROP TABLE EMPLOYEE;
c. ALTER :
It is used to alter the structure of the database. This change could be either to modify
the characteristics of an existing attribute or probably to add a new attribute.
Syntax: To add a new column in the table
ALTER TABLE table_name ADD column_name COLUMN-definition;
d. TRUNCATE :
It is used to delete all the rows from the table and free the space containing the table.
Syntax : TRUNCATE TABLE table_name;
Example : TRUNCATE TABLE EMPLOYEE;
256120316009 page-
Database Management (DI03016041)
a. INSERT
b. UPDATE
c. DELETE
a. INSERT :
The INSERT statement is a SQL query. It is used to insert data into the row of a table.
Syntax: INSERT INTO TABLE_NAME (col1, col2, col3,.... col N) VALUES (value1,
value2, value3,.....valueN);
Or
INSERT INTO TABLE_NAME VALUES (value1, value2, value3,..... valueN);
For example: INSERT INTO javatpoint (Author, Subject) VALUES ("Sonoo", "DBMS");
b. UPDATE :
This command is used to update or modify the value of a column in the table.
For example : UPDATE students SET User_Name = 'Sonoo' WHERE Student_Id = '3'
c. DELETE :
It is used to remove one or more row from a table.
a. Grant
b. Revoke
256120316009 page-
Database Management (DI03016041)
4. Resources/Equipment Required
Sr. Instrument/Equipment/
Specification Quantity
No. Components/Trainer kit
Hardware: Computer Computer (i3-i5 preferable), RAM minimum
1
System 2 GB and onwards
2 As Per
Operating System Windows/ Linux
Batch
3 Software Oracle Size
I. Source code:
Write SQL queries to use Update, alter, rename, delete, truncate and distinct.
Table: ACCOUNT.
246120316047 page-
Database Management (DI03016041)
(b) Change the name and city where account number is A005. (new name = ‘kothari
nehal’and new city = ‘patan’).
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
_ ___________________________________________________________________________________________________________________________
(c) Display only those records where loan taken status is ‘YES’.
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
(d) Add the new column (address varchar2 (20)) into table ACCOUNT.
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
(e) Create another table ACCOUNT_TEMP (acc_no, name, balance) from table
ACCOUNT.
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
246120316047 page-
Database Management (DI03016041)
(g) Update the column balance for all the account holders. (Multiply the balance
by2 foreach account holders)
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
________________________________________________________________________________________________________________________
246120316047 page-
Database Management (DI03016041)
Table: LOAN.
(a) For each loan holders Add 100000 Rs. Amount into the column loan_amt.
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
(b) For each loan holders Increase the interest rate 2%.
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
(c) Display only those records where loan holder taken a loan in month of January.
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
246120316047 page-
Database Management (DI03016041)
(d) Modify the structure of table LOAN by adding one column credit_no
varchar2(4).
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
(f) Display the records of table LOAN by date wise in ascending order.
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
246120316047 page-
Database Management (DI03016041)
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
Table: INSTALLMENT.
(a) Change the Inst_Date ‘2-Feb-04’ to ’3-Mar-04’.
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
246120316047 page-
Database Management (DI03016041)
(c) Add the amount 5000 where loan no is ‘L003’ and ‘L002’.
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
246120316047 page-
Database Management (DI03016041)
Table: TRANSACTION.
(a) Insert any duplicate value and display all the records without any
duplicaterows.
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
___________________________________________________________________________________________________________________________
246120316047 page-
Database Management (DI03016041)
246120316047 page-
Database Management (DI03016041)
3) Which SQL command is used to remove all data from a table in a database
whilekeeping the table structure intact?
a) TRUNCATE b) DELETE
c) REMOVE d) CLEAN
K. References / Suggestions
1) [Link]
2) [Link]
3) [Link]
L. Assessment-Rubrics
Faculty
Marks Obtained Date
Signature
Program Implementation Student’s engagement
Correctness and Presentation in practical activities Total
(4) Methodology (3) (3) (10)
R1 R2 R3
246120316047 page-