DBMS Lab
DBMS Lab
DBMS Lab
AIM:
PROCEDURE
STEP 1: Start
STEP 3: Execute different Commands and extract information from the table.
STEP 4: Stop
DDL COMMANDS:
1. The Create Table Command: - It defines each column of the table uniquely. Each column has
minimum of three attributes, a name, data type and size.
Syntax:
Table created.
Syntax:
Table altered.
ENAME CHAR(10)
SAL NUMBER(7,2)
3. Dropping a column from a table.
Syntax:
Table altered.
SQL> desc emp;
Syntax:
Table altered.
Syntax:
Table renamed.
Syntax:
Truncate table <tablename>;
Table truncated.
7. Destroying tables.
Syntax:
Table dropped.
ERROR:
ORA-04043: object emp1 does not exist
CONSTRAINTS:
Create table tablename (column_name1 data_ type constraints, column_name2 data_ type
constraints …)
Example:
Create table stud1(sname varchar2(20) not null, rollno number(10) not null,dob date not null);
DOMAIN INTEGRITY
ENTITY INTEGRITY
RESULT:
AIM:
PROCEDURE
STEP 1: Start
STEP 2: Create the table with its essential attributes.
STEP 3: Insert the record into table
STEP 4: Update the existing records into the table
STEP 5: Delete the records in to the table
STEP 6: Stop
DML COMMANDS
DML commands are the most frequently used SQL commands and is used to query and
manipulate the existing database objects. Some of the commands are Insert, Select, Update, Delete.
Insert Command: This is used to add one or more rows to a table. The values are separated by
commas and the data types char and date are enclosed in apostrophes. The values must be entered in
the same order as they are defined.
Select Commands: It is used to retrieve information from the table. It is generally referred to as
querying the table. We can either display all columns in a table or only specify column from the
table.
Update Command: It is used to alter the column values in a table. A single column may be
updated or more than one column could be updated.
Delete command: After inserting row in a table we can also delete them if required. The delete
command consists of a from clause followed by an optional where clause.
1 row created.
SQL> create table emp(empno number(6) primary key,ename varchar2(20),job varchar2(13),deptno
number(3),sal number(7,2));
Table created.
Q2: Insert more than a record into emp table using a single insert command.
1 row created.
1 row created.
1 row created.
Q3: Update the emp table to set the salary of all employees to Rs15000/- who are working as
ASP
1 Mathi AP 1 10000
1 row created.
SQL> /
Enter value for empno: 5
Enter value for ename: Akalya
Enter value for job: AP
Enter value for deptno: 1
Enter value for sal: 10000
old 1: insert into emp values(&empno,'&ename','&job',&deptno,&sal)
new 1: insert into emp values(5,'Akalya','AP',1,10000)
1 row created.
SQL> /
Enter value for empno: 6
Enter value for ename: suresh
Enter value for job: lect
Enter value for deptno: 1
Enter value for sal: 8000
old 1: insert into emp values(&empno,'&ename','&job',&deptno,&sal)
new 1: insert into emp values(6,'suresh','lect',1,8000)
1 row created.
6 rows selected.
Q4: Create a pseudo table employee with the same structure as the table emp and insert rows into the
table using select clauses.
Table created.
Q7: List the records in the emp table orderby salary in ascending order.
SQL> select * from emp order by sal;
EMPNO ENAME JOB DEPTNO SAL
---------- -------- ------- ---------- ----------
1 Mathi AP 1 10000
5 Akalya AP 1 10000
2 Arjun ASP 2 15000
3 Gugan ASP 1 15000
4 Karthik Prof 2 30000
Q8: List the records in the emp table orderby salary in descending order.
SQL> select * from emp order by sal desc;
EMPNO ENAME JOB DEPTNO SAL
---------- --------- ----- ---------- ----------
4 Karthik Prof 2 30000
2 Arjun ASP 2 15000
3 Gugan ASP 1 15000
1 Mathi AP 1 10000
5 Akalya AP 1 10000
Q10: Display deptno from the table employee avoiding the duplicated values.
SQL> select distinct deptno from emp;
DEPTNO
----------
1
2
IMPLEMENTATION OF DATA AND BUILT IN FUNCTIONS IN SQL
CHARACTER/STRING FUNCTION:
UPP
---
HAI
LOW
---
hai
INITCAP('Hello’)
--------------
Hello World
LTR
---
hai
RTR
---
hai
RTRIM('
-------
hai
LENGTH('SRM')
----------------------
12
SUBSTR
------
lingam
LPAD('
------
***hai
REPLACE
-------
Danie
TRANSL
------
Cool
SYSDATE
---------
07-APR-10
ROUND(SYS
---------
07-APR-10
ADD_MONTH
---------
07-JUL-10
LAST_DAY(
---------
30-APR-10
NEXT_DAY(
---------
13-APR-10
NUMERIC FUNCTION
ROUND(15.6789)
--------------
16
CEIL(23.20)
-----------
24
FLOOR(34.56)
------------
34
TRUNC(15.56743)
---------------
15
SIGN(-345)
----------
-1
ABS(-70)
---------
70
MATH FUNCTION:
ABS(45)
---------
45
POWER(10,12)
------------
1.000E+12
EXP(10)
---------
22026.466
SQRT(225)
---------
15
SET OPERATORS
QUERIES:
Table created.
1 row created.
1 row created.
1 row created.
10 inventory hyd
US.COM
20 finance bglr
30 HR mumbai
Q1: Display all the dept numbers available with the dept and emp tables avoiding duplicates.
Solution:
SQL> select deptno from emp union select deptno from dept;
DEPTNO
----------
1
2
12
30
40
Q2: Display all the dept numbers available with the dept and emp tables.
SQL> select deptno from emp union all select deptno from dept;
DEPTNO
----------
1
2
2
1
12
1
2
30
40
9 rows selected.
Q3: Display all the dept numbers available in emp and not in dept tables and vice versa.
SQL> select deptno from emp minus select deptno from dept;
DEPTNO
----------
12
SQL> select deptno from dept minus select deptno from emp;
DEPTNO
----------
30
40
RESULT
AIM:
PROCEDURE
STEP 1: Start
STEP 2: Create the table with its essential attributes.
STEP 3: Insert the record into table
STEP 4: Update the existing records into the table
STEP 5: Delete the records in to the table
STEP 6: use save point if any changes occur in any portion of the record to undo its
original state.
STEP 7: use rollback for completely undo the records
STEP 8:use commit for permanently save the records.
TCL COMMANDS:
Queries:
Q1: Develop a query to grant all privileges of employees table into departments table
SQL> Grant all on employees to departments;
Grant succeeded.
Q2: Develop a query to grant some privileges of employees table into departments table
SQL> Grant select, update , insert on departments to departments with grant option; Grant
succeeded.
Q3: Develop a query to revoke all privileges of employees table from departments table
SQL> Revoke all on employees from departments;
Revoke succeeded.
Q4: Develop a query to revoke some privileges of employees table from departments table
SQL> Revoke select, update , insert on departments from departments; Revoke
succeeded.
Savepoint created.
1 Mathi AP 1 10000
1 row created.
AIM
To execute and verify the SQL commands for Nested &join Queries.
PROCEDURE
STEP 1: Start
STEP 2: Create two different tables with its essential attributes.
STEP 3: Insert attribute values into the table.
STEP 4: Create the Nested &join query from the above created table.
STEP 5: Execute Command and extract information from the tables.
STEP 6: Stop
NESTED QUERIES:
Q1: Display all employee names and salary whose salary is greater than minimum salary of the
company and job title starts with ‗M‘.
Solution:
SQL> select ename,sal from emp where sal>(select min(sal) from emp where job like 'A%');
ENAME SAL
-------------------- ----------
Arjun 12000
Gugan 20000
Karthik 15000
Q2: Issue a query to find all the employees who work in the same job as Arjun.
SQL> select ename from emp where job=(select job from emp where ename='Arjun');
ENAME
--------------
Arjun
Gugan
Q3: Issue a query to display information about employees who earn more than any employee
in dept 1.
SQL> select * from emp where sal>(select max(sal) from emp where empno=1);
INNER JOIN/ NATURAL JOIN/ JOIN: It is a binary operation that allows us to combine certain
selections and a Cartesian product into one operation.
OUTER JOIN: It is an extension of join operation to deal with missing information.
←
Left Outer Join: It takes tuples in the left relation that did not match with any
tuple in the right relation, pads the tuples with null values for all other attributes
from the right relation and adds them to the result of the natural join.
←
Right Outer Join: It takes tuples in the right relation that did not match with
any tuple in the left relation, pads the tuples with null values for all other
attributes from the left relation and adds them to the result of the natural join.
←
Full Outer Join: It combines tuples from both the left and the right relation and
pads the tuples with null values for the missing attributes and hem to the result of
the natural join.
Table created.
1 row created.
1 row created.
1 row created.
10 inventory hyd
US.COM
20 finance bglr
30 HR mumbai
Table created.
1 row created.
SQL>insert into emp2 values(222,'sandeep','clerk',333,20);
1 row created.
1 row created.
values(444,'madhu','engineer',222,40);
1 row created.
1.Equijoin:
A join which contains an equal to ‘=’ operator in this joins condition.
Using Clause:
On Clause:
SQL> select eno,ename,job,dname,loc from emp2 e join dept d on(e.dno=d.dno);
2.Non-Equijoin:
A join which contains an operator other than equal to ‘=’ in the join condition.
SQL> select eno,ename,job,dname,loc from emp2 e,dept d where e.dno>d.dno;
3.Self Join:
Joining the table itself is called self join.
4.Natural Join:
It compares all the common columns.
SQL> select eno, ename, job, dname, loc from emp2 natural join dept;
5. Cross Join:
This will give the cross product.
SQL> select eno,ename,job,dname,loc from emp2 cross join dept;
6.Outer Join:
It gives the non matching records along with matching records.
6.1 Left Outer Join:
This will display the all matching records and the records which are in left hand side table those
that are in right hand side table.
SQL> select eno,ename,job,dname,loc from emp2 e left outer join dept d on(e.dno= d.dno);
(OR)
SQL> select eno,ename,job,dname,loc from emp2 e,dept d where e.dno=d.dno(+);
AIM
STEP 1: Start
STEP 5: Execute different Commands and extract information from the View.
STEP 6: Stop
QUERIES:
Q1: The organization wants to display only the details of the employees those who are ASP.
View created.
Q2: The organization wants to display only the details like empno, empname, deptno,
deptname of the employees. (Vertical portioning)
SQL> create view empview1 as select ename,sal from emp;
View created.
DEPT TABLE
EMP TABLE
EMPVIEW VIEW
EMPVIEW1 VIEW
Q4: Execute the DML commands on the view created.
View dropped.
RESULT
AIM
PROCEDURE
STEP 1: Start
STEP 6: Stop
SYNONYMS
A synonym is an alias, that is, a form of shorthand used to simplify the task of referencing
a database object.
There are two categories of synonyms, public and private.
A public synonym can be accessed by any system user.
Private synonyms, on the other hand, belong to the system user that creates them and reside
in that user's schema.
A system user can grant the privilege to use private synonyms that they own to other
system users.
Examples:
SQL> select * from class;
NAME ID
---------- ----------
Anu 1
Brindha 2
Chinthiya 3
Divya 4
Ezhil 5
Fairoz 7
Hema 9
7 rows selected.
IDYARTHIPLUS.COM
Create synonym:
In order to create synonyms, we will need to have the CREATE SYNONYM privilege.
This privilege will be granted to us by the DBA.
We must have the CREATE PUBLIC SYNONYM privilege in order to create public synonyms.
NAME ID
---------- ----------
Anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
hema 9
kalai 20
8 rows selected.
NAME ID
---------- ----------
anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
hema 9
kalai 20
8 rows selected.
SQL> insert into class values('Manu',21);
1 row created.
VIDYARTHIPLUS.COM
SQL> select * from c1;
NAME ID
---------- ----------
anu 1
brindha 2
chinthiya 3
divya 4
ezhil 5
fairoz 7
hema 9
kalai 20
Manu 21
9 rows selected.
Drop Synonym:
In order to drop a public synonym we must include the PUBLIC keyword in the DROP
SYNONYM command.
In order to drop a public synonym, we must have the DROP PUBLIC SYNONYM
privilege.
DROP PUBLIC SYNONYM synonym_name;
Synonym dropped.
RESULT
AIM
PROCEDURE
STEP 1: Start
STEP 2: Create the table with its essential attributes.
STEP 3: Insert attribute values into the table.
STEP 4: Create the sequences from the above created table.
STEP 5: Execute different Commands.
STEP 6: Stop
SEQUENCES
Oracle provides the capability to generate sequences of unique numbers, and they are
called sequences.
Just like tables, views, indexes, and synonyms, a sequence is a type of database object.
Sequences are used to generate unique, sequential integer values that are used as primary
key values in database tables.
The sequence of numbers can be generated in either ascending or descending order.
Creation of table:
SQL> create table class(name varchar(10),id number(10));
Table created.
Insert values into table:
SQL> insert into class values('&name',&id);
Enter value for name: anu
Enter value for id: 1
Old 1: insert into class values('&name',&id)
new 1: insert into class values('anu',1)
1 row created.
SQL> /
Enter value for name: brindha
Enter value for id: 02
old1: insert into class values('&name',&id)
new1: insert into class values('brindha',02)
1 row created.
SQL> /
Enter value for name: chinthiya
Enter value for id: 03
old1: insert into class values('&name',&id)
new1: insert into class values('chinthiya',03)
1 row created.
SQL> select * from class;
NAME ID
---------- ----------
Anu 1
brindha 2
chinthiya 3
Create Sequence:
SQL> create sequence s_1
2 start with 4
3 increment by 1
4 maxvalue 100
5 cycle;
Sequence created.
1 row created.
AIM:
ALGORITHM:
STEP1:Start
STEP6: End
SQL> create table bill(name varchar2(10), address varchar2(20), city varchar2(20), unit
number(10));
Table created.
SQL> /
1 row created.
SQL> /
Enter value for name: maya
SQL> /
1 row created.
SQL> declare
3 b bill %ROWTYPE;
4 begin
5 open c;
4);
20 Else
5);
22 end if;
23 end if;
24 end loop;
25 close c;
26 end;
27 /
RESULT:
Thus the program to implement cursors was executed and output was verified successfully.
PROGRAM FOR STUDENT GRADE CALCULATION
AIM
To write a PL/SQL block to display the student name, marks whose average mark is above
60%.
ALGORITHM
STEP1:Start
STEP3:Insert the values into the table and Calculate total and average of each student
STEP4: Execute the procedure function the student who get above 60%.
STEP6: End
1 row created.
SQL> /
SQL> /
1 row created.
SQL> /
1 row created.
2 tot number;
3 average number;
5 s std %ROWTYPE;
6 begin
7 open c;
10 fetch c into s;
11 tot:=s.mark1+s.mark2+s.mark3;
12 average:=floor(tot/3);
13 if(c % notfound)then
14 exit;
15 else
26 else
end if;
29 end if;
30 end loop;
31 close c;
32 end;
33 /
RESULT:
Thus the program to implement cursors was executed and output was verified successfully.
EX.NO:9 IMPLEMENTATION OF TRIGGERS
AIM
To develop and execute a Trigger for before and after update, Delete, Insert operations on
a table.
PROCEDURE
STEP 1: Start
STEP 3:Specify the operations (update, delete, insert) for which the trigger
has to be executed.
STEP 4: Execute the Trigger procedure for both Before and After sequences
STEP 5: Carryout the operation on the table to check for Trigger execution.
STEP 6: Stop
Table created.
3 begin
4 :new.tot:=:new.m1+:new.m2+:new.m3;
5 :new.avrg:=:new.tot/3;
7 :new.result:='pass';
8 else
9 :new.result:='Fail';
3 end if;
4 end;
5 /
Trigger created.
1 row created.
Table created.
SQL>
3 when(new.age>100)
4 begin
5 RAISE_APPLICATION_ERROR(-20998,'INVALID ERROR');
6 end;
SQL> /
Trigger created.
1 row created.
ERROR at line 1:
RESULT:
AIM
PROCEDURE
STEP 1: Start
STEP 6: Stop
Table created.
--------- --------------------
101 Nithya
102 Maya
5 end insert_num;
6 /
Procedure created.
--------- --------------------
101 Nithya
102 Maya
103 SCOTT
FUNCTION TO FIND FACTORIAL
AIM
PROCEDURE
STEP 1: Start
STEP 6: Stop
6 return number is
7 i number(10);
8 f number:=1;
9 begin
11 f:=f*i;
12 end loop;
13 return f;
10 end;
11 /
Function created.
FACT(2)
---------
2
RESULT:
AIM:
DESCRIPTION:
1.PL/SQL provides a feature to handle the Exceptions which occur in a PL/SQL Block known as
exception Handling. Using Exception Handling we can test the code and avoid it from exiting
abruptly.
2.When an exception occurs amessages which explains its cause is recieved.
3.PL/SQL Exception message consists of three parts.
• Type of Exception
• An Error Code
• A message
Syntax :
DECLARE
Declaration section
BEGIN
Exception section
EXCEPTION
WHEN ex_name1 THEN
-Error handling statements
WHEN ex_name2 THEN
-Error handling statements
WHEN Others THEN
-Error handling statements
END;
SQL> DECLARE
1) N INTEGER:=&N;
2) A EXCEPTION;
3) B EXCEPTION;
4) BEGIN
RTHIPLUS.COM
1) IF MOD(N,2)=0 THEN
2) RAISE A;
3) ELSE
4) RAISE B;
1) END IF;
2) EXCEPTION
3) WHEN A THEN
4) DBMS_OUTPUT.PUT_LINE('THE INPUT IS EVEN.....')
5) WHEN B THEN
6) DBMS_OUTPUT.PUT_LINE('THE INPUT IS ODD.....');
7) END;
8) /
Enter value for n: 20
old 2: N INTEGER:=&N;
new 2: N INTEGER:=20;
THE INPUT IS EVEN.....
SQL> /
Enter value for n: 21
old 2: N INTEGER:=&N;
new 2: N INTEGER:=21;
THE INPUT IS ODD.....
2) L_NUM2 NUMBER;
3) BEGIN
4) L_NUM1 := 10;
5) L_NUM2 := 0;
6) DBMS_OUTPUT.PUT_LINE('RESULT:'||L_NUM1/L_NUM2);
8)
10) EXCEPTIONWWW.VIDYARTHIPLUS.COM
1) WHEN ZERO_DIVIDE THEN
2) DBMS_OUTPUT.PUT_LINE(SQLCODE);
3) DBMS_OUTPUT.PUT_LINE(SQLERRM);
4) END;
5) /
-1476
RESULT
Thus the PL/SQL program that handles exception has been implemented and output was verified.
EX.NO:12 DATABASE DESIGN USING E-R MODEL AND NORMALIZATION
ER diagram:
Chen Notation
Chen Notation
Representing Relationships
• 1:1 Relationships. The key of one relation is stored in the second relation. Look
at example queries to determine which key is queried most often.
• 1:N Relationships.
Parent - Relation on the "1" side. Child
- Relation on the "Many" side.
• Represent each Entity as a relation.
Copy the key of the parent into the child relation.
• CUSTOMER (CustomerID (key), Name, Address, ...)
ORDER (OrderNum (key), OrderDate, SalesPerson, CustomerID (fk))
• M:N Relationships. Many to Many relationships can not be directly implemented in
relations.
• Solution: Introduce a third Intersection relation and copy keys from original two
relations.
Chen Notation
RESULT:
Thus the ER Database design using E-R model and Normalization was implemented
successfully.
EX.NO: 13 EMPLOYEE INFORMATION- DATABASE CONNECTIVITY
AIM:
To create the following Form using Database Grid tool in Visual Basic.
DESCRIPTION:
1. The connection of database with the visual basic form window is made possible using
Database Grid.
2. The database Table to be connected is specified in the record source field in the
dbgrid properties window.
3. Text boxes or labels associated with the data fields are connected to the data grid using the
“Data source” and the filed in the data table is connected using “Data Field”
from the properties window of the respective textboxes or labels
The following commands are used to perform the data grid operations
1) Data_grid_name.recordset.addnew Adds new record
2) Data_grid_name.recordset.delete Deletes a record
3) Data_grid_name.recordset.movenext Moves to the next record
4) Data_grid_name.recordset.moveprevious Moves to the previous record
5) Data_grid_name.recordset.movefirst Moves to the first record
6) Data_grid_name.recordset.movelast Moves to the last record
W.VIDYARTHIPLUS.COM
1) Data_grid_name.recordset.edit Prepares a row of a Recordset for editing
2) Data_grid_name.recordset.update Cancels any pending Update statements.
CODING:
Data1.Recordset.MoveFirst
End Sub
Data1.Recordset.MoveLast
End Sub
Data1.Recordset.MovePrevious
End Sub
Private Sub Command4_Click()
Data1.Recordset.MoveNext
End Sub
Data1.Recordset.MoveLast
Data1.Recordset.AddNew
End Sub
Data1.Recordset.Delete
Data1.Recordset.MoveLast
End Sub
Data1.Recordset.Edit
Data1.Recordset.Update
End SubWWW.VIDYARTHIPLUS.COM
Private Sub Command8_Click()
End
End Sub
RESULT:
Thus the employee information was created using DBGrid tool in Visual Basic
EX.NO: 14 IMPLEMENTATION OF PAYROLL PROCESSING
AIM:
STEPS:
1. Create a database for payroll processing which request the using SQL
4. Click add button and select oracle in ORA home 90, click finish
5. A window will appear given the data source home as oracle and select TNS source name as lion
and give the used id as SWTT
7. The above procedure must be follow except the table , A select the table as salary
8. Write appropriate Program in form each from created in VB from each from created in VB form
project.
AIM :
To design and implement the pay roll processing System.
STEPS:
1.Create the DB for banking system source request the using SQL.
2.Establishing ODBC connection.
3.VISUAL BASIC APPLICATION:-
Create standard exe project in to and design ms from in request format
To add ADODC project select component and check ms ADO data control click ok Now
the control is added in the tool book
Create standard exe project in to and design ms from in request format
4.ADODC CONTEOL FOR ACCOUNT FROM:- Click customs and property window and window
will appear and select ODBC data source name as oracle and click apply as the some window.
End Sub
SOURCE CODE FOR FORM 2
Private Sub CLEAR_Click()
Text1.Text = ""
Text2.Text = ""
Text3.Text = ""
End Sub
Private Sub
DELETE_Click()
Adodc1.Recordset.DELETE MsgBox "record deleted"
Adodc1.Recordset.MoveNext If Adodc1.Recordset.EOF = True Then
Adodc1.Recordset.MovePrevious
End If
End Sub
Private Sub EXIT_Click()
Unload Me
End Sub
Private Sub
HOME_Click()
Form1.Show
End Sub
Private Sub
INSERT_Click() Adodc1.Recordset.AddNew
End Sub
Private Sub
TRANSACTION_Click()
Form3.Show
End Sub
Private Sub UPDATE_Click() Adodc1.Recordset.UPDATE MsgBox "record updated
successfully"
End Sub
SOURCE CODE FOR FORM 3
Private Sub ACCOUNT_Click()
Form2.Show
End Sub
Private Sub CLEAR_Click()
Text1.Text = ""
Text2.Text = ""
End Sub
Private Sub
DEPOSIT_Click()
Dim s As String s = InputBox("enter the amount to be deposited")
Text2.Text = Val(Text2.Text) + Val(s) A = Text2.Text MsgBox "CURRENT BALANCE IS Rs" +
Str(A) Adodc1.Recordset.Save Adodc1.Recordset.UPDATE
End Sub
Private Sub
EXIT_Click()
Unload Me
End Sub
Private Sub
HOME_Click()
Form1.Show End
Sub Private Sub
WITHDRAW_Click()
Dim s As String s = InputBox("enter the amount to be deleted")
Text2.Text = Val(Text2.Text) - Val(s) A = Text2.Text MsgBox "current balance is Rs" +
Str(A)
Adodc1.Recordset.Save
Adodc1.Recordset.UPDATE
End Sub
RESULT:
Thus the banking system was designed and implemented successfully.
_________________________________________________________________________________
AIM :
To design and implement the library management System.
STEPS:
4. Click add button and select oracle in ORA home 90, click finish
5. A window will appear given the data source home as oracle and select TNS source name as
lion and give the used id as SWTT
7. The above procedure must be follow except the table , A select the table as library
8. Write appropriate Program in form each from created in VB from each from created in VB
form project.
CREATE TABLE Status ( code INTEGER, description CHAR(30), PRIMARY KEY (code) );
CREATE TABLE Media( media_id INTEGER, code INTEGER, PRIMARY KEY (media_id),
CREATE TABLE Card( num INTEGER, fines REAL, ID INTEGER, PRIMARY KEY (num),
CREATE TABLE Checkout( media_id INTEGER, num INTEGER, since CHAR(10), until
CREATE TABLE Location( name CHAR(64), addr CHAR(256), phone CHAR(30), PRIMARY
KEY (name) );
CREATE TABLE Hold( media_id INTEGER, num INTEGER, name CHAR(64), until
CHAR(10),
CREATE TABLE Stored_In( media_id INTEGER, name char(64), PRIMARY KEY (media_id),
FOREIGN KEY (media_id) REFERENCES Media ON DELETE CASCADE, FOREIGN
CREATE TABLE Librarian( eid INTEGER, ID INTEGER NOT NULL, Pay REAL, Loc_name
CREATE TABLE Video( title CHAR(128), year INTEGER, director CHAR(64), rating REAL,
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password) VALUES
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password) VALUES
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password) VALUES
(64937, 'Roger Hurst', '974 Bingamon Branch Rd, Bensenville, IL 60106', '08/22/1973',
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password) VALUES
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password) VALUES
(79916, 'Steven Jensen', '93 Sunny Glen Ln, Garfield Heights, OH 44125', '12/14/1968',
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password) VALUES
(93265, 'David Bain', '4356 Pooh Bear Lane, Travelers Rest, SC 29690', '08/10/1947',
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password) VALUES
(58359, 'Ruth P. Alber', '3842 Willow Oaks Lane, Lafayette, LA 70507', '02/18/1976',
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password) VALUES
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password) VALUES
(57054, 'John M. Byler', '279 Raver Croft Drive, La Follette, TN 37766', '11/27/1954',
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password) VALUES
(49312, 'Kevin Spruell', '1124 Broadcast Drive, Beltsville, VA 20705', '03/04/1984',
INSERT INTO Card(num, fines, ID) VALUES ( 5767052, 0.0, 60201); INSERT
INTO Card(num, fines, ID) VALUES ( 9780749, 0.0, 64937); INSERT INTO
Card(num, fines, ID) VALUES ( 1521412, 0.0, 31430); INSERT INTO Card(num,
fines, ID) VALUES ( 3920486, 0.0, 79916); INSERT INTO Card(num, fines, ID)
VALUES ( 2323953, 0.0, 93265); INSERT INTO Card(num, fines, ID) VALUES
( 4387969, 0.0, 58359); INSERT INTO Card(num, fines, ID) VALUES ( 4444172, 0.0,
88564); INSERT INTO Card(num, fines, ID) VALUES ( 2645634, 0.0, 57054);
INSERT INTO Card(num, fines, ID) VALUES ( 3688632, 0.0, 49312); INSERT INTO
Location(name, addr, phone) VALUES ('Texas Branch', '4832 Deercove Drive, Dallas,
TX 75208', '214-948-7102');
INSERT INTO Location(name, addr, phone) VALUES ('Illinois Branch', '2888 Oak
(2, 'In Transit'); INSERT INTO Status(code, description) VALUES (3, 'Checked Out');
INSERT INTO Status(code, description) VALUES (4, 'On Hold'); INSERT INTO
Media( media_id, code) VALUES (8733, 1); INSERT INTO Media( media_id, code)
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES ('978-
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES ('978-
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES ('978-
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES ('978-
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES ('978-
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES ('978-
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES ('978-
0374105235', 'Long Way Gone: Memoirs of a Boy Soldier', 'Ishmael Beah', 2007,
916, 10.0);
INSERT INTO Book(ISBN, title, author, year, dewey, price) VALUES ('978-
INSERT INTO Checkout(media_id, num, since, until) VALUES (2220, 9780749, '02/15/2007',
'03/15/2007');
INSERT INTO Video(title, year, director, rating, price) VALUES ('Die Hard',
'Aliens', 1986);
'Aliens', 1986);
Hard', 1988);
LIKE '%<user input>%' AND B.year <= <user input> AND B.year >=
<user input>;
/* Find all copies of a book (used for placing holds or viewing detailed
information). */
AND V.director LIKE '%<user input>%' AND V.rating >= <user input>; /*
Find all copies of a video (used for placing holds or viewing detailed
information). */
SELECT S.description FROM Status S, Media M WHERE S.code = M.code AND M.media_id =
<user input>;
/* Create a new Hold */
INSERT INTO Hold(media_id, num, name, until, queue) VALUES
+ 1 );
FROM Card CR
UNION
FROM Card CR
/* *\
\* */
INSERT INTO Customer(ID, name, addr, DOB, phone, username, password) VALUES (<user
input>, <user input>, <user input>, <user input>, <user input>, <user input>, <user input>, );
/* Find a customer */
nvl((SELECT 'Librarian'
FROM Librarian L
FROM Customer C
UPDATE Media
Find the next Hold entry for a given media */ SELECT H.num, H.name, H.until
FROM Hold H
UPDATE Stored_In
Hold H
WHERE H.queue = 1 AND H.name = <user input> AND H.media_id = <user input> AND
(<user input>, <user input>, <user input>, <user input>, <user input>, <user
input>);
input>, <user input>, <user input>, <user input>, <user input>); /* Add a
INSERT INTO BookMedia(media_id, ISBN) VALUES (<user input>, <user input>); /* Add
<user input>;
<user input>;
AIM :
PROCEDURE:
Step1: create a new project in visual basic using the option file---> new project.
Step2: In the form use the front end tools in the toolbox like textbox, label,command button and
create a front end Design for the simple calculator.
Step3: Open the properties window for the tool sand select properties. Now the properties
window is opened.
Step4: Set properties for each tool in the form like caption, name, etc.
IPLUS.COM
Step5: Double click each and every tool to open the project code window.
and division.
Step7: The code is Automatically compiled at the end of each line while pressing the Enter key.
Step7: now execute the code by click the F5 button in the keyboard or select
Run--->start.
Step8: after successfully executing the project create the executable file by
CODING:
Dim a, b, c, d As Integer
End Sub
Private Sub button1_Click()
End Sub
End Sub
End Sub
W.VIDYARTHIPLUS.COM
Private Sub button4_Click()
End Sub
End Sub
End Sub
End Sub
End Sub
a = Val(display.Text)
display.Text = ""
d=1
ARTHIPLUS.COM
End Sub
a = Val(display.Text)
display.Text = ""
d=2
End Sub
a = Val(display.Text)
display.Text = ""
d=3
End Sub
a = Val(display.Text)
display.Text = ""
d=4
End Sub
b = Val(display.Text)
If d = 1 Then
c=a+b
display.Text = c
ElseIf d = 2 Then
c=a-b
.VIDYARTHIPLUS.COM
display.Text = c
ElseIf d = 3 Then
c=a*b
display.Text = c
ElseIf d = 4 Then
c=a/b
display.Text = c
End If
End Sub
a=0
b=0
c=0
display.Text = ""
End Sub
End
End Sub
End Sub
RESULT:
Thus the simple calculator created by using the front end tools was executed successfully.
Viva Questions
1. What is SQL?
Structured Query Language
2. What is database?
A database is a logically coherent collection of data with some inherent meaning, representing
some aspect of real world and which is designed, built and populated with data for a specific
purpose.
3. What is DBMS?
It is a collection of programs that enables user to create and maintain a database. In other
words it is general-purpose software that provides the users with the processes of defining,
constructing and manipulating the database for various applications.
4. What is a Database system?
The database and DBMS software together is called as Database system.
5. Advantages of DBMS?
←
Redundancy is controlled.
←
Unauthorized access is restricted.
←
Providing multiple user interfaces.
←
Enforcing integrity constraints.
←
Providing backup and recovery.
6.Disadvantage in File Processing System?
←
Data redundancy & inconsistency.
←
Difficult in accessing data.
←
Data isolation.
←
Data integrity.
←
Concurrent access is not possible.
←
Security Problems.
7.Describe the three levels of data abstraction?
There are three levels of abstraction:
←
Physical level: The lowest level of abstraction describes how data are stored.
←
Logical level: The next higher level of abstraction, describes what data are stored in database
and what relationship among those data.
← View level:The highest level of abstraction describes only part of entire database.
8.Define the "integrity rules"
There are two Integrity rules.
← Entity Integrity:States that ―Primary key cannot have NULL value‖
← Referential Integrity:States that ―Foreign Key can be either a NULL value or
should be Primary Key value of other relation.
9. What is Data Independence?
Data independence means that the application is independent of the storage structure and
access strategy of data‖.
Two types of Data Independence:
Physical Data Independence: Modification in physical level should not affect the
logical level.
Logical Data Independence: Modification in logical level should affect the view
level.
A collection of conceptual tools for describing data, data relationships data semantics and
constraints.
13. What is E-R model?
This data model is based on real world that consists of basic objects called entities and of
relationship among these objects. Entities are described in a database by a set of attributes.
14. What is Object Oriented model?
This model is based on collection of objects. An object contains values stored in instance
variables within the object.
15. What is an Entity?
It is an 'object' in the real world with an independent existence.
16. What is an Entity type?
It is a collection (set) of entities that have same attributes.
17. What is an Entity set?
It is a collection of all entities of particular entity type in the database.
18. What is an Extension of entity type?
The collections of entities of a particular entity type are grouped together into an
entity
set.
19. What is an attribute?
It is a particular property, which describes the entity.
20. What is a Relation Schema and a Relation?
A relation Schema denoted by R(A1, A2, …, An) is made up of the relation name
R and the list of attributes Ai that it contains.
A relation is defined as a set of tuples. Let r be the relation which contains set
tuples (t1, t2, t3, ...,tn).
21. What is degree of a Relation?
It is the number of attribute of its relation schema.
22. What is Relationship?
It is an association among two or more entities.
23. What is Relationship set?
49. What is system catalog or catalog relation? How is better known as?
A RDBMS maintains a description of all the data that it contains, information about every
relation and index that it contains. This information is stored in a collection of relations maintained
by the system called metadata. It is also called data dictionary.
50. What is meant by query optimization?
The phase that identifies an efficient execution plan for evaluating a query that has the least
estimated cost is referred to as query optimization.
51.What are the different phases of transaction?
Different phases are
← Analysis phase
← Redo Phase
← Undo phase
52. What is durability in DBMS?
Once the DBMS informs the user that a transaction has successfully completed, its effects
should persist even if the system crashes before all its changes are reflected on disk. This property is
called durability.
53. What do you mean by atomicity and aggregation?
Atomicity:
Either all actions are carried out or none are. Users should not have to worry about the effect
of incomplete transactions. DBMS ensures this by undoing the actions of incomplete transactions.
Aggregation:
A concept which is used to model a relationship between a collection of entities and
relationships. It is used when we need to express a relationship among relationships.
55. What is a checkpoint and when does it occur?
A Checkpoint is like a snapshot of the DBMS state. By taking checkpoints, the DBMS can
reduce the amount of work to be done during restart in the event of subsequent crashes.
68. Which part of the RDBMS takes care of the data dictionary? How
Data dictionary is a set of tables and database objects that is stored in a special area of the
database and maintained exclusively by the kernel.
69. What is the job of the information stored in data-dictionary?
The information in the data dictionary validates the existence of the objects, provides access
to them, and maps the actual physical storage location.