Case study dbms
Case study dbms
D.B.M.S LAB-FILE
DDL COMMANDS:
In this section, We will cover the following DDL commands as
fallow.
1. Create
2. Alter
3. Truncate
4. Drop
5. Rename
Create:
This command is used to creation a table or databases in SQL.
Alter:
This command is used to add, delete & change column in the existing table.
Truncate:
This command is used to remove all rows from the table, but the truncate of the
table still exists.
Drop:
This command is used to remove an existing table along with its structure from the
database.
Rename:
It is possible to change name of table with or without data in it using simple
rename command.
Query:
➢ Create database comp;
✓ Query ok, 1 row affected.
➢ Show databases;
➢ Use comp;
✓ Database changed
➢ Desc emp;
➢ Alter table emp add comp_address varchar(50);
DML COMMANDS:
The DML commands in structured query language change the data
present in the SQL database. We can easily access, store, modify, update and delete the
existing records from the databases using DML commands.
1. Select
2. Insert
3. Update
4. Delete
Insert:
Insert command allows users to insert data in database tables.
Select:
Select the data in table to fetching the records.
Update:
Update query is used to update a record in table.
Delete:
Delete query is used to delete a row in a table.
Query:
➢ Insert into empl(1,”Ram”,”98676545”,”jaunpur”,”tcs”,5000);
➢ Select * from empl;
✓ Empty set
PROGRAM NO: 3
AIM:- Write SQL queries using logical operations (=, <, >)
Logical operation to use a particular fetching the records in table with the table the help of
some operation.
Query:
➢ Select * from empl where e_id=2;
Query:
➢ Select ProductName from Products where Productid = ALL (Select Productid from
OrderDetails where Quantity = 10);
➢ Select * from products where price > some (Select price from products where price >
20);
➢ Select 30+20;
✓ 50
➢ Select 17%5;
✓ 2
➢ Select 60-40;
✓ 20
➢ Select 20/2;
✓ 10
Relational Algebra:
Relational algebra is a procedural query language. It gives a step-by-step process to obtain
the result of the query. It uses operators to perform queries.
Where:
p is used as a propositional logic formula which may use connectors like: AND OR and
NOT. These relational can use as relational operators like =, ≠, ≥, <, >, ≤.
➢ σ BRANCH_NAME="perryride" (LOAN)
Aim: -Write SQL queries for extracting data from more than one
table.
Description: -SELECT statement is used to retrieve fields from multiple
tables. To do so, we need to use join query to get data from multiple tables.
Query: -
SELECT vbspu3.GID, vbspu3.PID, vbspu3.Asset, vbspu1.FirstName,
Vbspu2.LastName
FROM vbspu3
ON vbspu3.GID=vbspu1.ID
ON vbspu3.GID=vbspu.ID
OUTPUT: --
PRACTICAL: -07
Description: -Indexes are used to retrieve data from the database more quickly than
otherwise. The users cannot see the indexes, they are just used to speed up searches/queries.
A view contains rows and columns, just like a real table. The fields in a view are fields from
one or more real tables in the database.
Query: -
OUTPUT: -
Harsh Kolkata 90
Pratik Delhi 80
Dhanraj Bihar 95
Ram Rajasthan 85
ON StudentDetails(Name,Address,Marks);
OUTPUT: -
Index Name Address Marks
1 Harsh Kolkata 90
2 Pratik Delhi 80
3 Dhanraj Bihar 95
4 Ram Rajasthan 85
PRACTICAL-08
Description: - A JOIN clause is used to combine rows from two or more tables,
based on a related column between them.
Query: -
SELECT Customers.customer_id, Customers.first_name, Orders.item
FROM Customers
JOIN Orders
ON Customers.customer_id = Orders.customer_id;
OUTPUT: -
PRACTICAL-09
Query: -
DECLARE
-- Variable declaration
BEGIN
/*
*/
dbms_output.put_line(msg);
END;
OUTPUT: -
PRACTICAL-10
Description: -If any error occurs with any of the SQL grouped statements, all
changes need to be aborted. The process of reversing changes is
called rollback.
Ouery:-
DELETE FROM Student WHERE AGE = 20;
COMMIT;
OUTPUT: -
OUTPUT:-
SAVEPOINT SP1;
//Savepoint created.
DELETE FROM Student WHERE AGE = 20;
//deleted
SAVEPOINT SP2;
//Savepoint created.
OUTPUT:-