Record DBMS
Record DBMS
- F/ TL / 021
Rev.00 Date 20.03.2020
RECORD NOTEBOOK
DEPARTMENT
OF
NAME : INDUJA.D
REGISTER NO : 231191101061
YEAR/SEM/SEC : II/III/AA
BONAFIDE CERTIFICATE
NESTED QUERIES
6(a) 8/10/2024
AGGREGATION OPERATIONS
6(b)
8/10/2024
COMMANDS
10 5/11/2024
EXECUTION JOIN OPERATIONS
NUMBERS
AIM:
DDL Commands:
There are five commands in DATA DEFINITION LANGUAGE. They Are as follows:
1. Create.
2. Alter.
3. Drop.
4. Truncate.
5. Rename.
1. CREATE
EXAMPLE: Create Students table with the following attributes: StudentID, Name,
DateOfBirth, Gender and Phone.
INDUJA D 1 231191101061
OUTPUT:
2. ALTER:
This alter command is used to change the structure of the database. The alter command is
used along with the following sub-commands
a) ADD
SYNTAX:
ALTER TABLE <table_name> ADD (A1D1,A2D2,A3D3,. AnDn);
INDUJA D 2 231191101061
OUTPUT:
MODIFY: This alter command is used to change the attribute name of the database.
SYNTAX:
ALTER TABLE <table_name> MODIFY (column_namedata_type);
EXAMPLE: Modify the attribute Phone from table Students and make numeric.
INDUJA D 3 231191101061
OUTPUT:
DROP:
The drop DDL command is used to delete an object from the database.
SYNTAX:
DROP TABLE <table_name>;
INDUJA D 4 231191101061
OUTPUT:
TRUNCATE:
The truncate command is used to remove all the records and attributes from the table
including the space allotted for the record.
SYNTAX:
TRUNCATE table<table_name>;
INDUJA D 5 231191101061
RENAME:
The rename command is used to rename an object in the database.
SYNTAX:
RENAME<old table_name> TO <new table_name>;
RESULT:
INDUJA D 6 231191101061
EX.NO:2 EXECUTION OF DML COMMANDS DATE: 24/9/2024
AIM:
INSERT:
This DML command is used to insert records into a table relation.
SYNTAX:
INSERT INTO <table_name> VALUES (‘A11’5,‘A2’,. ....); OR
EXAMPLE:
Insert into Students_details values (‘211011011101’, ‘Payal’, ‘2000-08-
24’,’F’,’9567859624’, ‘A-102, Garden Street’,96)
INDUJA D 7 231191101061
OUTPUT:
SELECT:
The select statement is used to retrieve data from the database.
Select statement can be used to display all the records in the relation table by using [*] for
selecting all the attributes. For displaying the records without duplicity, the DISTINCT
keyword is used.
SYNTAX:
INDUJA D 8 231191101061
EXAMPLE:
EXAMPLE:
⮚ Display the attributes StudentID and Name from the Students_details table.
SELECT StudentID, Name FROM Students_details;
OUTPUT:
EXAMPLE:
Display the records in the attribute Name without duplicates from the Students_details
table. SELECT DISTINCT Name FROM Students_details;
INDUJA D 9 231191101061
OUTPUT:
UPDATE
UPDATE statement is used to modify existing rows.
1. To update all rows data in a table at a time.
2. To update a specific row data in a table by using the “where” condition.
SYNTAX:
UPDATE table_name SET column=value
Eg: update students_details set name='Siva’;
update the value of a single field
OUTPUT:
INDUJA D 10 231191101061
DELETE :To remove single or multiple existing records from the database tables
Eg: delete students_details;
To delete all of the rows in the table.
Eg: Deleting the row that contains particular data
DELETE FROM table_name WHERE condition
OUTPUT:
RESULT :
INDUJA D 11 231191101061
EX.NO:3 EXECUTION OF DCL COMMANDS DATE: 1/10/2024
AIM:
CREATE USER :
Syntax : CREATE USER user_account IDENTIFIED BY password;
INDUJA D 12 231191101061
GRANT :
Syntax :GRANT privileges_names ON object TO user;
Explanation:
● privileges_name: These are the access rights or privileges granted to the user.
● object: It is the name of the database object to which permissions are being
granted. In the case of granting privileges on a table, this would be the table
name.
● user: It is the name of the user to whom the privileges would be granted.
REVOKE :
This statement is used to revoke some or all of the privileges which have been granted to a
user in the past.
Syntax:
REVOKE privileges ON object FROM user;
Parameters Used:
● object: It is the name of the database object from which permissions are being
revoked. In the case of revoking privileges from a table, this would be the table name.
● user: It is the name of the user from whom the privileges are being revoked.
INDUJA D 13 231191101061
RESULT :
INDUJA D 14 231191101061
EX.NO:4 EXECUTION OF TCL COMMANDS DATE: 1/10/2024
AIM:
SAVEPOINT :
Syntax:
SAVEPOINT savepoint_name;
ROLLBACK :
roll back the transaction using the ROLLBACK command to the savepoint INS, which we
have created before executing the DELETE query.
Syntax:
ROLLBACK TO savepoint_name;
Example : create a table and insert values set a savepoint called Insertion
INDUJA D 15 231191101061
OUTPUT :
RESULT :
INDUJA D 16 231191101061
EX.NO:5 EXECUTION OF INSERT COMMANDS DATE: 1/10/2024
AIM:
Syntax:
insert into <table_name> values(‘A11’5,‘A2’, ....... );
Example :
insert into students_details values(101,'sam','12-10-1999','m',12323231,'chennai')
INDUJA D 17 231191101061
Unique Constraints:
This constraint ensures that no two rows have the same values in the specified column.
eg: create table employee_details (ecode numeric NOT NULL UNIQUE, ename char(20)
NOT NULL, gender char (1) NOT NULL, grade char (2), gross decimal);
Primary Constraints:
This constraint declares a column as the PRIMARY KEY of the table. This constraint is
similar to UNIQUE constraint except that only one column (or one group of columns) can be
applied in this constraint. The PRIMARY KEY cannot allow NULL values.
eg: create table employee_details (ecode numeric NOT NULL PRIMARY KEY, ename
char(20) NOT NULL, sex char (1) NOT NULL, grade char (2), grossdecimal);
INDUJA D 18 231191101061
ARITHMETIC EXPRESSION:
Arithmetic operations like addition, subtraction, multiplication, division can be performed on
the records in an attribute. It can also be performed on constants of tuples. Select clause may
also contain arithmetic involving +, *, -, /.
EXAMPLE: Find the loan_no, branch_name and amount*100 in the loan_details relation
table.
select loan_no, branch_name, amount*100 from loan_details1173;
OUTPUT:
WHERE clause: The where clause is used to conditionally select data from a table; where
clause can be added to the select statement.
EXAMPLE: Display the loan_no having a loan at the Perryridge branch and having amount
greater than Rs.1200 from loan_details relation.
select loan_no from loan_details where branch_name = ‘Perryridge’ and amount>1200;
INDUJA D 19 231191101061
OUTPUT:
INDUJA D 20 231191101061
EXAMPLE: Find all the customers who have the loan from the bank. Also find their loan_no
and loan amount.
select customer_name ,loan_no, amount from loan_details, borrower_details where
loan_details.loan_no = borrower_details.loan_no;
OUTPUT:
RESULT :
INDUJA D 21 231191101061
Ex:6 (a) NESTED QUERIES Date: 8/10/2024
Aim:
Syntax:
Select column1,column2,..from table1 where column1 IN (select column1 from table2
where codition)
Operators Used :
IN, NOT IN, ALL, ANY , EXIST, NOT EXIST
IN Connective :
Syntax:. Select attribute_name from relation_1 where IN (select from );
NOT IN Connective :
Syntax: select from where condition NOT IN (select from relation_02);
Example: ➢ Find all the customers who have both a loan and an account at the bank.
INDUJA D 22 231191101061
OUTPUT :
Example: ➢ Find the customer who have loan at the bank but do not have an account
at the bank.
Example: ➢ Find all customers who have loan at the bank and names are neither Smith
nor Jones.
INDUJA D 23 231191101061
select distinct customer_name from borrower_details where customer_name NOT IN
(‘Thomas’,’sam’);
OUTPUT:
EXIST:
Example:
CREATESALESTABLEWITHSALAES_ID,EMP_ID,SALE_AMT
INSERT VALUES INTO THE SALES TABLE.
SELECT emp_name
FROM employees
INDUJA D 24 231191101061
OUTPUT :
ALL:
Example:
Find the names of all employees who have made sales greater than $1000.
SELECT emp_name
FROM employees
WHERE emp_id = ALL (SELECT emp_id
FROM sales
WHERE sale_amt > 1000);
INDUJA D 25 231191101061
OUTPUT:
RESULT:
INDUJA D 26 231191101061
Ex:6 (b) AGGREGATION OPERATORS Date: 8/10/2024
Aim:
Aggregate functions are often used with the GROUP BY clause of the SELECT statement.
The GROUP BY clause splits the result-set into groups of values and the aggregate function
can be used to return a single value for each group.
The most commonly used SQL aggregate functions are:
● MIN() - returns the smallest value within the selected column
● MAX() - returns the largest value within the selected column
● COUNT() - returns the number of rows in a set
● SUM() - returns the total sum of a numerical column
● AVG() - returns the average value of a numerical column
MIN() : select min(studentid) from students_details;
OUTPUT:
INDUJA D 27 231191101061
MAX(): SELECT MAX(MARKS) FROM student_details;
OUTPUT:
OUTPUT:
INDUJA D 28 231191101061
ALIAS NAME: SELECT MIN(MARKS) as Minimum_marks FROM student_details;
OUTPUT:
COUNT() : function returns the number of rows that matches a specified criterion.
SELECT COUNT(*) FROM STUDENT_DETAILS;
OUTPUT:
INDUJA D 29 231191101061
SELECT SUM(MARKS) FROM STUDENT_DETAILS;
OUTPUT:
INDUJA D 30 231191101061
AVG() : function returns the average value of a numeric column.
SELECT AVG(MARKS) FROM STUDENT_Details; OUTPUT
:
RESULT:
INDUJA D 31 231191101061
Ex: 6 (c) GROUPING & ORDERING COMMAND Date: 22/10/2024
Aim:
Description:
Group By: Used to group rows that have the same values into summary rows, typically
used with aggregate functions like SUM, COUNT, AVG, etc…
GROUP BY Syntax :
SELECT column_name(s) FROM table_name WHERE condition
GROUP BY column_name(s) ORDER BY column_name(s);
Order By: Sort the result set either in ascending or descending order.
INDUJA D 32 231191101061
Example: ➢ lists the number of acc_id in each branch, sorted high to low
RESULT:
INDUJA D 33 231191101061
EX.NO:7 SELECT,FROM AND WHERE CLAUSE (sqlite3) DATE: 29/10/2024
AIM:
ALGORITHM:
Program :
import sqlite3
# Connecting to sqlite
# connection object
connection_obj = sqlite3.connect('student1.db')
# cursor object
INDUJA D 34 231191101061
cursor_obj = connection_obj.cursor()
connection_obj.execute(
"""INSERT INTO student_sqlite1 (Email,Name,Score) VALUES
("Sam.com","CSE",50)""")
connection_obj.execute(
"""INSERT INTO student_sqlite1 (Email,Name,Score) VALUES
("Thomas.com","AI",55)""")
connection_obj.execute(
"""INSERT INTO student_sqlite1 (Email,Name,Score) VALUES
("Vicky.com","AI",60)""")
INDUJA D 35 231191101061
cursor_obj = connection_obj.cursor()
cursor_obj.execute(statement)
print("All the data")
output = cursor_obj.fetchall()
for row in output:
print(row)
connection_obj.commit()
INDUJA D 36 231191101061
RESULT:
INDUJA D 37 231191101061
EX.NO: 8 SET OPERATION DATE: 29/10/24
Aim:
Description: SET operators are special type of operators which are used to combine the
result of two queries.
Operators covered under SET operators are:
1. UNION
2. UNION ALL
3. INTERSECT
4. MINUS
1. Union :
OUTPUT:
INDUJA D 38 231191101061
2. UNION ALL:
● This operator combines all the records from both the queries.
● Duplicate rows will be not be eliminated from the results obtained after
performing the UNION ALL operation.
3. INTERSECT :
○ It is used to combine two SELECT statements, but it only returns the records
which are common from both SELECT statements.
OUTPUT :
INDUJA D 39 231191101061
4. MINUS
○ It displays the rows which are present in the first query but absent in the second
query with no duplicates.
OUTPUT:
RESULT:
INDUJA D 40 231191101061
EX.NO:9 STRING OPERATIONS DATE: 5/11/24
Aim:
Concatenation :
Output:
Substring :
INDUJA D 41 231191101061
Output:
String Length :
INDUJA D 42 231191101061
String Replacement
Output:
Changing Case :
INDUJA D 43 231191101061
Output:
Trimming
Spaces
● Operation: Remove spaces from the start, end, or both ends of a string.
● Functions:
○ TRIM() – Removes specified characters or spaces from both ends.
○ LTRIM() – Removes characters from the left.
○ RTRIM() – Removes characters from the right.
Output:
INDUJA D 44 231191101061
Padding
Output:
Finding Position :
INDUJA D 45 231191101061
Output:
Reversing a String:
Output:
RESULT :
INDUJA D 46 231191101061
EX.NO:10 EXECUTION OF JOIN OPERATION DATE: 5/11/24
Aim:
Syntax :
SELECT column_name(s) FROM table1 INNER JOIN table2 ON
table1.column_name = table2.column_name;
Perform an inner join between the employee and sales relation based on the emp_id.
OUTPUT:
INDUJA D 47 231191101061
LEFT OUTER JOIN:
The LEFT JOIN keyword returns all records from the left table (table1), and
the matching records from the right table (table2).
Syntax :
SELECT column_name(s) FROM table1 LEFT JOIN table2
ON table1.column_name = table2.column_name;
Example :
SELECT employee.emp_name, sales.sale_id FROM
employee
LEFT JOIN sales ON employee.emp_id = sales.emp_id ORDER
BY employee.emp_name;
OUTPUT :
INDUJA D 48 231191101061
RIGHT OUTER JOIN:
The RIGHT JOIN keyword returns all records from the right table (table2), and the
matching records from the left table (table1).
Syntax:
SELECT column_name(s)
FROM table1
RIGHT JOIN table2
ON table1.column_name = table2.column_name;
Example :
SELECT sales.sale_id,employee.emp_name FROM sales RIGHT
JOIN employee ON sales.emp_id = employee.emp_id ORDER BY
sales.sale_id;
OUTPUT :
RESULT:
INDUJA D 49 231191101061
EX.NO:11 CONTOL SATEMENT (For loop) DATE: 12/11/2024
Aim:
Algorithm:
Program :
DECLARE
i NUMBER := 1;
BEGIN
LOOP
EXIT WHEN i>10;
DBMS_OUTPUT.PUT_LINE(i); i
:= i+1;
END LOOP;
END;
OUTPUT:
INDUJA D 50 231191101061
RESULT:
INDUJA D 51 231191101061
EX.NO:12 CONTROL STATEMENT (While loop) DATE: 12/11/2024
Aim:
Algorithm:
Program :
DECLARE
i INTEGER := 1;
BEGIN
WHILE i <= 10 LOOP
DBMS_OUTPUT.PUT_LINE(i);
i := i+1;
END LOOP;
END;
INDUJA D 52 231191101061
OUTPUT:
RESULT:
INDUJA D 53 231191101061
EX.NO:13 CONTROL STATEMENT (for reverse loop) DATE: 19/11/2024
Aim:
Algorithm:
Program :
DECLARE
VAR1 NUMBER;
BEGIN
VAR1:=1;
FOR VAR2 IN REVERSE 1..10
LOOP
DBMS_OUTPUT.PUT_LINE (VAR1*VAR2);
END LOOP;
END;
INDUJA D 54 231191101061
OUTPUT :
RESULT:
INDUJA D 55 231191101061
EX.NO:14 CONTROL STATEMENT (loop end loop) DATE: 19/11/2024
Aim:
Algorithm:
Program :
Declare I numeric (3);
Begin
I:=1;
Loop dbms_output.put_line(i);
I:=i+1;
If(i=10) then exit;
End if;
End loop;
End;
INDUJA D 56 231191101061
OUTPUT :
RESULT:
INDUJA D 57 231191101061
EX.NO:15 IMPLEMENTATION OF SUM OF EVEN NUMBER DATE: 26/11/2024
Aim:
Algorithm:
Program :
DECLARE
-- Declare variable num
num NUMBER(3) :=2 ;
sum1 NUMBER(4) := 0;
BEGIN
WHILE num <= 20 LOOP
-- Display even number
dbms_output.Put_line(num);
-- Sum of even numbers
sum1 := sum1 + num;
-- Next even number
num := num + 2;
-- End loop
END LOOP;
-- Display even number
dbms_output.Put_line('Sum of even numbers is ' || sum1);
END;
INDUJA D 58 231191101061
OUTPUT :
RESULT:
INDUJA D 59 231191101061
EX.NO:16 IMPLEMENTATION OF SUM OF ODD NUMBERS DATE: 26/11/24
Aim:
Algorithm:
PROGRAM:
DECLARE
-- Declare variable num
num NUMBER(3) :=1 ;
sum1 NUMBER(4) := 0;
BEGIN
WHILE num <= 20 LOOP
-- Display even number
dbms_output.Put_line(num);
-- Sum of even numbers
sum1 := sum1 + num;
-- Next even number
num := num + 2;
-- End loop
END LOOP;
-- Display even number
dbms_output.Put_line('Sum of oddnumbers is ' || sum1);
END;
INDUJA D 60 231191101061
OUTPUT:
RESULT :
INDUJA D 61 231191101061
EX.NO:17 IMPLEMENT OF SERIES GENERATION DATE: 10/12/2024
Aim:
Algorithm:
Program:
DECLARE
n NUMBER := 10; -- Number of terms in the Fibonacci series
a NUMBER := 0;
b NUMBER := 1;
c NUMBER;
BEGIN
DBMS_OUTPUT.PUT_LINE('Fibonacci Series:');
DBMS_OUTPUT.PUT_LINE(a);
DBMS_OUTPUT.PUT_LINE(b);
INDUJA D 62 231191101061
c := a + b;
DBMS_OUTPUT.PUT_LINE(c);
a := b;
b := c;
END LOOP;
END;
OUTPUT:
RESULT:
INDUJA D 63 231191101061
EX.NO:18 IMPLEMENTATION OF SUB PROGRAM DATE: 10/12/2024
Aim:
Algorithm:
Program :
DECLARE
i number;
j number;
k number;
PROCEDURE findAdd(num1 IN number, num2 IN number, sum OUT number) IS
BEGIN
sum := num1 + num2;
END;
BEGIN
i:= 5;
j:= 5;
findAdd(i, j, k);
dbms_output.put_line(' The sum is : ' || k);
END;
INDUJA D 64 231191101061
OUUTPUT :
RESULT :
INDUJA D 65 231191101061
EX.NO:19 IMPLEMENTATION OF CURSOR USING PL/SQL DATE: 17/12/2024
Aim:
Algorithm:
Program :
DECLARE
c_id customers.id%type;
c_name customers.name%type;
c_addr customers.address%type;
CURSOR c_customers is
SELECT id, name, address FROM customers;
BEGIN
OPEN c_customers;
LOOP
FETCH c_customers into c_id, c_name, c_addr;
EXIT WHEN c_customers%notfound;
dbms_output.put_line(c_id || ' ' || c_name || ' ' || c_addr);
END LOOP;
INDUJA D 66 231191101061
CLOSE c_customers;
END;
OUTPUT:
RESULT :
INDUJA D 67 231191101061
EX.NO:20 IMPLEMENTATION OF CONTROL DATE: 17/12/2024
STATEMENT(if-elsif-end if)
Aim:
Algorithm:
Program :
DECLARE
mark NUMBER:=55;
BEGIN
dbms_output.put_line('program started');
IF(mark>=70) THEN
dbms_output.put_line('Grade A');
ELSIF(mark>=40 AND mark < 70) THEN
dbms_output.put_line('Grade B');
ELSIF(mark>=35 AND mark<40) THEN
INDUJA D 68 231191101061
dbms_output.put_line('Grade C');
end if;
dbms_output.put_line('Program completed');
end;
OUTPUT:
RESULT :
INDUJA D 69 231191101061