Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Ce316p Labmanual

Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

Department of Computer Sciences and Engineering

B.Tech Semester 4
Subject: Database Management System
Subject Code: CE316P
List of Experiments

Sr. Date of
No. Title submission Sign Remark
1 To study DDL-create and DML-insert commands. 22-12-24

2 Create the below given table and insert the data 29-12-24
accordingly.
To Perform various data manipulation commands, 05-05-24
3 aggregate functions and sorting concept on all
created tables
4 To study Single-row functions. 12-01-24
5 Displaying data from Multiple Tables (join). 19-01-24

6 To apply the concept of Aggregating Data using 02-02-24


Group functions.
7 To solve queries using the concept of sub query 09-02-24

8 To Manipulate Data using various SQL 15-03-24


commands.
9 To apply the concept of security and privileges. 22-03-24

10 To study Transaction control commands. 05-04-24

Database Management System CE316P


PRACTICAL -1

AIM: To study DDL-create and DML-insert commands.

Create tables according to the following definition.


1. CREATE TABLE DEPOSIT (ACTNO VARCHAR2(5) ,CNAME VARCHAR2(18) , BNAME
VARCHAR2(18) , AMOUNT NUMBER(8,2) ,ADATE DATE);
2. CREATE TABLE BRANCH(BNAME VARCHAR2(18),CITY VARCHAR2(18));
3. CREATE TABLECUSTOMERS(CNAME VARCHAR2(19) ,CITY VARCHAR2(18));
4. CREATE TABLE BORROW(LOANNO VARCHAR2(5), CNAME VARCHAR2(18),
BNAME VARCHAR2(18), AMOUNT NUMBER (8,2));
Insert the data as shown below.

TABLE : DEPOSIT

TABLE : BRANCH

Database Management System CE316P


TABLE : CUSTOMERS

TABLE : BORROW

Database Management System CE316P


From the above given tables perform the following queries:
1. Describe deposit, branch.
2. Describe borrow, customers.
3. List all data from table DEPOSIT.
4. List all data from table BORROW.
5. List all data from table CUSTOMERS.
6. List all data from table BRANCH.
7. Give account no and amount of depositors.
8. Give name of depositors having amount greater than 4000.
9. Give name of customers who opened account after date '1-12-96'.

Database Management System CE316P


PRACTICAL -2
AIM: Create the below given table and insert the data accordingly.

Create Table Job (job_id, job_title, min_sal, max_sal);

Create table Employee (emp_no, emp_name, emp_sal, emp_comm, dept_no);

Create table deposit(a_no,cname,bname,amount,a_date);

Create table borrow(loanno,cname,bname,amount);

Database Management System CE316P


Insert following values in the table Employee.

Insert following values in the table job.

Insert following values in the table deposit.

Database Management System CE316P


Perform following queries
1. Retrieve all data from employee, jobs and deposit.
2. Give details of account no. and deposited rupees of customershaving account opened between
dates 01-01-06 and 25-07-06.

3. Display all jobs with minimum salary is greater than 4000.


4. Display name and salary of employee whose department no is 20. Give alias name to name of
employee.
5. Display employee no,name and department details of thoseemployee whose department lies
in(10,20)
6. Display all employee whose name start with ‘A’ and third character is ‘‘a’.
7. Display name, number and salary of those employees whose name is 5 characters long and first
three characters are ‘Ani’.
8. Display the non-null values of employees and also employee name second character should be
‘n’ and string should be 5 character long.
9. Display the null values of employee and also employee name’s third character should be ‘a’.
10. What will be output if you are giving LIKE predicate as ‘%\_%’ ESCAPE‘\’

Database Management System CE316P


PRACTICAL -3
AIM: To Perform various data manipulation commands, aggregate functions and sorting concept
on all created tables.

1. List total deposit from deposit.


2. List total loan from karolbagh branch.
3. Give maximum loan from branch vrce.
4. Count total number of customers.
5. Count total number of customer’s cities.
6. Create table supplier from employee with all the columns.
7. Create table sup1 from employee with first two columns.
8. Create table sup2 from employee with no data.
9. Insert the data into sup2 from employee whose second charactershould be ‘n’ and string should
be 5 characters long in employee name field.
10. Delete all the rows from sup1.
11. Delete the detail of supplier whose sup_no is 103.
12. Rename the table sup2.
13. Destroy table sup1 with all the data.
14. Update the value dept_no to 10 where second character of emp. Name is ‘m’.
15. Update the value of employee name whose employee number is 103.

Database Management System CE316P


PRACTICAL -4
AIM: To study Single-row functions.

1. Write a query to display the current date. Label the column Date.
2. For each employee, display the employee number, job, salary, and salary increased by 15% and
expressed as a whole number. Label the column New Salary
3. Modify your query no 4.(2) to add a column that subtracts the oldsalary from the new salary.
Label the column Increase.
4. Write a query that displays the employee’s names with the first letter capitalized and all other
letters lowercase, and the length of the names, for all employees whose name starts with J, A, or
M. Give each column an appropriate label. Sort the results by the employees’ last names.
5. Write a query that produces the following for each employee: earns monthly.
6. Display the hiredate of emp in a format that appears as Seventh of June 1994 12:00:00 AM.
7. Write a query to calculate the annual compensation of all employees (sal+comm.).

Database Management System CE316P


PRACTICAL -5
AIM: Displaying data from Multiple Tables (join).

1. Give details of customers ANIL.


2. Give name of customer who are borrowers and depositors andhaving living city nagpur.
3. Give city as their city name of customers having same living branch.
4. Write a query to display the last name, department number, and department name for all
employees.
5. Create a unique listing of all jobs that are in department 30. Include the location of the
department in the output.
6. Write a query to display the employee name, department number, and for all employees who
work in RAJKOT
7. Display the employee last name and employee number along with their manager’s last name and
manager number. Label the columns Employee, Emp#, Manager, and Mgr#, respectively.
8. Create a query to display the name and hire date of any employee hired after employee SCOTT.

Database Management System CE316P


PRACTICAL -6
AIM: To apply the concept of Aggregating Data using Group functions.

1. List total deposit of customer having account date after 1-jan-96.


2. List total deposit of customers living in city Nagpur.
3. List maximum deposit of customers living in bombay.
4. Display the highest, lowest, sum, and average salary of all employees. Label the columns
Maximum, Minimum, Sum, and Average, respectively. Round your results to the nearest whole
number.
5. Write a query that displays the difference between the highest and lowest salaries. Label the
column DIFFERENCE.
6. Create a query that will display the total number of employees and, of that total, the number of
employees hired in 1995, 1996, 1997, and 1998
7. Find the average salaries for each department without displaying the respective department
numbers.
8. Write a query to display the total salary being paid to each job title, within each department.
9. Find the average salaries > 2000 for each department without displaying the respective
department numbers.
10. Display the job and total salary for each job with a total salary amount exceeding 3000, in which
excludes president and sorts the list by the total salary.
11. List the branches having sum of deposit more than 5000 and located in city bombay.

Database Management System CE316P


PRACTICAL -7
AIM: To solve queries using the concept of sub query.

1. Write a query to display the last name and hire date of any employee in the same department as
SCOTT. Exclude SCOTT.
2. Give name of customers who are depositors having same branch cityof mr. sunil.
3. Give deposit details and loan details of customer in same city where pramod is living.
4. Create a query to display the employee numbers and last names of all employees who earn more
than the average salary. Sort the results in ascending order of salary.
5. Give names of depositors having same living city as mr. anil and having deposit amount greater
than 2000.
6. Display the department number, name, and job for every employee in the Accounting
department.
7. List the name of branch having highest number of depositors.
8. Give the name of cities where in which the maximum numbers of branches are located.
9. Give name of customers living in same city where maximum depositors are located.

Database Management System CE316P


PRACTICAL -8
AIM: To Manipulate Data using various SQL commands.

Following queries need to perform:


1. Give 10% interest to all depositors.
2. Give 10% interest to all depositors having branch vrce
3. Give 10% interest to all depositors living in nagpur and having branch city bombay.
4. Write a query which changes the department number of all employees with empno 7788’s job to
employee 7844’current department number.
5. Transfer 10 Rs from account of anil to sunil if both are having same branch.
6. Give 100 Rs more to all depositors if they are maximum depositors in their respective branch.
7. Delete depositors of branches having number of customers between 1 to 3.
8. Delete deposit of vijay.
9. Delete borrower of branches having average loan less than 1000.

Database Management System CE316P


PRACTICAL - 9
AIM: To apply the concept of security and privileges.

This chapter describes Point Base security and privileges. Schemas are an integral part of security in
Point Base. When creating a Point Base user, they do not have any access privileges to schemas or other
data objects within the database. The Point Base RDBMS only permits the schema owner to grant
privileges to the schema and data objects within the schema. The schema owner can grant privileges to
the following data objects in the schema:
Tables
Columns
SQL Procedures and Functions
Table 1 describes the privileges that the schema owner can grant users for tables and columns:
Table 1 : User Privileges for Tables and Columns

Privilege Privilege Description


Statements

DELETE Allows a user to delete rows from tables within the schema

INSERT Allows a user to insert rows of data into tables within the schema

REFERENCES Allows a user to set up references to primary keys within the


schema
SELECT Allows a user to select rows from tables within the schema

TRIGGER Allows a user to create triggers on tables within the schema

UPDATE Allows a user to update rows in tables within the schema

Allows users to execute functions or stored procedures within the


EXECUTE schema

Database Management System CE316P


Granting and Revoking Privileges
When a PointBase database is first created the only user is the default user PUBLIC with a password of
PUBLIC. The PUBLIC user owns the default PUBLIC schema. For security reasons, PointBase does not
recommend using this schema to store sensitive data. Like any PointBase user, PUBLIC must be granted
the appropriate privileges to access data objects in schema owned by other users.
The PUBLIC user can be used initially to create new users and new schema. The PUBLIC user will own
any new schema that it creates unless otherwise specified during schema creation. New users are then
able to create their own new schema and users, and grant appropriate privileges on schema that they own.
All new users must be granted privileges to use the PUBLIC schema if this is required.
To grant the ability for a user to pass a privilege on to other users once granted, you must specify the
optional WITH GRANT OPTION qualifier when granting the privilege.
GRANT Statement Syntax
GRANT privilege-list
ON object
TO user-list [ WITH GRANT OPTION ]

Use the GRANT statement to grant privileges on a data object. The following describes the GRANT
statement syntax.
Privilege-list Syntax
privilege [ , privilege [ , privilege ]...] | ALL PRIVILEGES
Privilege Syntax
SELECT [ ( column-name [ , column-name ]...)]
| DELETE
| INSERT [ ( column-name [ , column-name ]...)]
| UPDATE [ ( column-name [ , column-name ]...)]
| REFERENCES [ ( column-name [ , column-name ]...)]
| TRIGGER [ ( column-name [ , column-name ]...)]
| EXECUTE

Database Management System CE316P


Usage Notes
• If you do not include one or more of these privileges in the GRANT statement, an error will be
raised.
• If the optional column-names are not specified for the SELECT, INSERT, UPDATE,
REFERENCES and TRIGGER privileges, the GRANT is applied to every column in the table to
which the grant is applied.
• If you execute a GRANT statement that contains privileges that you don't have or for which you
do not have the right to grant, then PointBase raises an error.
Object Syntax
[ TABLE ] table-name
|SPECIFIC routine_type specific_routine-name
|routine_type routine_name (parameter_types_list) [ TRIGGER ] trigger-name
Usage Notes
• If you grant a privilege on an SQL Function or Procedure, then the user can only EXECUTE that
SQL Function or Procedure. The user cannot access tables that the SQL Function or Procedure
uses.
User-list Syntax
user [ , user ]... [WITH GRANT OPTION] | PUBLIC
Usage Notes
• If you do not specify WITH GRANT OPTION, the user cannot pass the same privilege on to
others. However, if you do specify WITH GRANT OPTION, you have given the user
permission to pass on the privilege to other users.
• Granting a privilege to the user PUBLIC only grants the privilege to the default PointBase
PUBLIC user and is not the same as granting a global privilege to all users.
• If you grant a privilege with the optional WITH GRANT OPTION and then grant the same
privilege without this option (without first revoking the original privilege) the user retains the
WITH GRANT OPTION.

Database Management System CE316P


Examples

• The following statement grants the SELECT privilege on the CUSTOMER_TBL table to the
user MARKETING_MGR.
GRANT SELECT
ON customer_tbl
TO marketing_mgr;
• The following GRANT statement allows the user FINANCIAL_MGR to delete, insert and
update rows from the DISCOUNT_CODE_TBL table; it also allows this user to grant the same
privileges to others.
GRANT DELETE,INSERT,UPDATE
ON discount_code_tbl TO financial_mgr
WITH GRANT OPTION;
• The following GRANT statement allows the user HR_MGR to have ALL PRIVILEGES on the
table SALES_REP_DATA_TBL. However, the user HR_MGR will only be granted privileges
that the user granting the privileges has the right to grant. For example, if the user granting the
privileges does not have the right to grant DELETE privileges, the HR_MGR will not have the
delete privilege.
GRANT ALL PRIVILEGES
ON sales_rep_data_tbl TO hr_mgr
REVOKE Statement Syntax
REVOKE [ GRANT OPTION FOR ] privilege_list
ON object
FROM user_name [ RESTRICT | CASCADE ]
The REVOKE statement takes privileges away from users. The arguments are similar to the GRANT
statement. The major difference is the additional RESTRICT or CASCADE keyword and the GRANT
OPTION FOR clause. The following describes the optional clauses GRANT OPTION FOR and
RESTRICT or CASCADE.
NOTE: If none of the privileges that you are trying to revoke actually exist, an error is raised.
Database Management System CE316P
RESTRICT | CASCADE
If you use RESTRICT keyword, the privilege will be revoked only from the specified user. If the
specified user granted had the WITH GRANT OPTION and granted the same privilege to other users,
they will retain the privilege.
If you use CASCADE, it will revoke the privilege and any dependent privileges as a result of your
grant. A dependent privilege is one that could exist, if you granted the privilege that you're trying to
revoke, which is what you are trying to achieve as a result of your REVOKE statement.
If the optional RESTRICT or CASCADE keywords are not used, PointBase uses RESTRICT by
default.
GRANT OPTION FOR
If he optional GRANT OPTION FOR clause is used, the WITH GRANT OPTION right is revoked. The
actual privilege itself is not revoked. the GRANT OPTION is revoked. CASCADE and RESTRICT
may be used in the same way as a normal REVOKE statement.

Database Management System CE316P


PRACTICAL - 10
AIM: To study Transaction control commands.

TCL Commands in SQL- Transaction Control Language Examples: Transaction Control Language can
be defined as the portion of a database language used for maintaining consistency of the database and
managing transactions in database. A set of SQL statements that are co-related logically and executed
on the data stored in the table is known as transaction. In this tutorial, you will learn different TCL
Commands in SQL with examples and differences between them.
1. Commit Command
2. Rollback Command
3. Savepoint Command
TCL Commands in SQL- Transaction Control Language Examples
The modifications made by the DML commands are managed by using TCL commands. Additionally, it
makes the statements to grouped together into logical transactions.
TCL Commands
There are three commands that come under the TCL:
1. Commit
The main use of Commit command is to make the transaction permanent. If there is a need for any
transaction to be done in the database that transaction permanent through commit command. Here is the
general syntax for the Commit command:
COMMIT;
For Example
UPDATE STUDENT SET STUDENT_NAME = ‘Maria’ WHERE STUDENT_NAME =
‘Meena’; COMMIT;
By using the above set of instructions, you can update the wrong student name by the correct one and
save it permanently in the database. The update transaction gets completed when commit is used. If
commit is not used, then there will be lock on ‘Meena’ record till the rollback or commit is issued.

Database Management System CE316P


Now have a look at the below diagram where ‘Meena’ is updated and there is a lock on her record. The
updated value is permanently saved in the database after the use of commit and lock is released.

2. Rollback

Using this command, the database can be restored to the last committed state. Additionally, it is also
used with savepoint command for jumping to a savepoint in a transaction.
The general syntax for the Rollback command is mentioned below: Rollback to savepoint-name;
For example

UPDATE STUDENT SET STUDENT_NAME = ‘Manish’ WHERE STUDENT_NAME

Database Management System CE316P


= ‘Meena’; ROLLBACK;
This command is used when the user realizes that he/she has updated the wrong information after the
student name and wants to undo this update. The users can issues
ROLLBACK command and then undo the update. Have a look at the below tables to know better about
the implementation of this command.

3. Savepoint
The main use of the Savepoint command is to save a transaction temporarily. This way users can
rollback to the point whenever it is needed.
The general syntax for the savepoint command is mentioned below: savepoint savepoint-name;
For Example

Following is the table of a school class

Database Management System CE316P


Use some SQL queries on the above table and then watch the results INSERT into CLASS VALUES
(101, ‘Rahul);
Commit;
UPDATE CLASS SET NAME= ‘Tyler’ where id= 101 SAVEPOINT A;
INSERT INTO CLASS VALUES (102, ‘Zack’);
Savepoint B;
INSERT INTO CLASS VALUES (103, ‘Bruno’)
Savepoint C;

Select * from Class; The result will look like


Now rollback to savepoint B Rollback to B;
SELECT * from Class;

Now rollback to savepoint A rollback to A;


Database Management System CE316P
SELECT * from class;

Database Management System CE316P

You might also like