Dbms Lab Manual
Dbms Lab Manual
Dbms Lab Manual
NAME:
ENROLLMENTNO:
BATCHNO:
YEAR:
CERTIFICATE
Date of Submission:-
DEPOSIT
BRANCH
CUSTOMERS
BORROW
DEPOSIT:
INSERT INTO DEPOSIT VALUES('100',’ANIL’,'VRCE',1000,'1-MAR-95');
INSERT INTO DEPOSIT VALUES('101','SUNIL','AJNI',5000,'4-JAN-96');
INSERT INTO DEPOSIT VALUES('102','MEHUL','KAROLBAGH',3500,'17-NOV-95');
INSERT INTO DEPOSIT VALUES('104','MADHURI','CHANDI',1200,'17-DEC-95');
INSERT INTO DEPOSITVALUES('105','PRMOD','M.G.ROAD',3000,'27-MAR-96');
INSERT INTO DEPOSIT VALUES('106','SANDIP','ANDHERI',2000,'31-MAR-96');
INSERT INTO DEPOSIT VALUES('107','SHIVANI','VIRAR',1000,'5-SEP-95');
INSERT INTO DEPOSIT VALUES('108','KRANTI','NEHRUPLACE',5000,'2-JUL-95');
INSERT INTO DEPOSIT VALUES('109','MINU','POWAI',7000,'10-AUG-95');
BRANCH:
INSERT INTO BRANCH VALUES('VRCE','NAGPUR');
INSERT INTO BRANCH VALUES('AJNI','NAGPUR');
INSERT INTO BRANCH VALUES('KAROLBAGH','DELHI');
INSERT INTO BRANCH VALUES('CHANDI','DELHI');
INSERT INTO BRANCH VALUES('DHARAMPETH','NAGPUR');
INSERT INTO BRANCH VALUES('M.G.ROAD','BANGLORE');
INSERT INTO BRANCH VALUES('ANDHERI','BOMBAY');
INSERT INTO BRANCH VALUES('VIHAR','BOMBAY');
INSERT INTO BRANCH VALUES('NEHRU PLACE','DELHI');
INSERT INTO BRANCH VALUES('POWAI','BOMBAY');
CUSTOMER:
INSERT INTO CUSTOMERS VALUES ('ANIL','CALCUTTA');
INSERT INTO CUSTOMERS VALUES ('SUNIL','DELHI');
INSERT INTO CUSTOMERS VALUES ('MEHUL','BARODA');
INSERT INTO CUSTOMERS VALUES ('MANDAR','PATNA');
INSERT INTO CUSTOMERS VALUES ('MADHURI','NAGPUR');
INSERT INTO CUSTOMERS VALUES ('PRAMOD','NAGPUR');
INSERT INTO CUSTOMERS VALUES ('SANDIP','SURAT');
INSERT INTO CUSTOMERS VALUES ('SHIVANI','BOMBAY');
INSERT INTO CUSTOMERS VALUES ('KRANTI','BOMBAY');
INSERT INTO CUSTOMERS VALUES ('NAREN','BOMBAY');
BORROW:
INSERT INTO BORROW VALUES ('201','ANIL','VRCE',1000);
INSERT INTO BORROW VALUES ('206','MEHUL','VRCE',5000);
INSERT INTO BORROW VALUES ('311','SUNIL','DHARAMPETH',3000);
INSERT INTO BORROW VALUES ('321','MADHURI','ANDHERI',2000);
INSERT INTO BORROW VALUES ('375','PRMOD','VIHAR',8000);
INSERT INTO BORROW VALUES ('481','KRANTI','NEHRU PLACE',3000);
DESC DEPOSIT;
DESC BRANCH;
2. Describe borrow, customers.
DESC BORROW;
DESC CUSTOMERS;
AIM: Create the below given table and insert the data accordingly.
4. Display name and salary of employee whose department no is 20. Give alias
name to name of employee.
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’.
9. Insert the data into sup2 from employee whose second charactershould be ‘n’
and string should be 5 characters long in employee name field.
14. Update the value dept_no to 10 where second character of emp. nameis ‘m’.
15. Update the value of employee name whose employee number is 103.
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.
5. Write a query that produces the following for each employee: earns monthly.
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.
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 employeehired after
employee SCOTT.
4. Display the highest, lowest, sum, and average salary of allemployees. Label the
columns Maximum, Minimum, Sum, and Average, respectively. Round your
results to the nearest whole number.
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 displayingthe respective
department numbers.
8. Write a query to display the total salary being paid to each job title, within each
department.
SELECT DEPT_NO,SUM(EMP_SAL) FROM EMPLOYEE GROUP BY
DEPT_NO;
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 salaryamount 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 locatedin city
bombay.
1. Write a query to display the last name and hire date of any employeein 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 citywhere pramod is
living.
4. Create a query to display the employee numbers and last names ofall employees
who earn more than the average salary. Sort the results in ascending order of
salary.
6. Display the department number, name, and job for every employee inthe
Accounting department.
SELECT D.DEPT_NO,D.DEPT_NAME,E.JO
D.DEPT_NO,D.DEPT_NAME,E.JOB_ID
B_ID FROM DEPARTMENT
D,EMPLOYEE E WHERE D.DEPT_NO=E.DEPT_NO AND D.DEPT_NAME
=’ACCOUNTING’;
8. Give the name of cities where in which the maximum numbers of branches are
located.
SELECT B1.CITY FROM BRANCH B1 GROUP BY B1.CITY HAVING COUNT
(B1.BNAME) > ALL (SELECT COUNT(B2.BNAME) FROM BRANCH B2
WHERE B1.CITY = B2.CITY GROUP BY B2.CITY);
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.
Transfer 10 Rs from account of anil to sunil if both are having same branch.
5. Give 100 Rs more to all depositors if they are maximum depositors in their
respective branch.
This chapter describes PointBase security and privileges. Schemas are an integral part of
security in PointBase. When creating a PointBase user, they do not have any access privileges
to schemas or other data objects within the database. The PointBase 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:
Privilege Privilege
Statements Description
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
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 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 Syntax
| DELETE
| EXECUTE
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
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.
Examples
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.
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.
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.
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.
PRACTICAL - 10
1. Commit Command
2. Rollback Command
3. Savepoint Command
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
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
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.
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.
Rollback to savepoint-name;
For example
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.
savepoint savepoint-name;
For Example
Use some SQL queries on the above table and then watch the results
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