Dbms Record
Dbms Record
EX.NO:1
INSERTING, DELETING, UPDATING ANDRETRIEVING TABLES AND
TRANSACTION CONTROL
DATE:
STATEMENTS
AIM :
To create table and Execute Data Definition Commands, Data Manipulation Commands for Inserting,Deleting, Updating And
Retrieving Tables and Transaction Control Statements
EMP_NO NUMBER(5)
EMP_NAME VARCHAR2(30)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE
CREATION OF TABLE WITH PRIMARY KEY:
SQL> create table emp1978(emp_no number(5) primary key,emp_name varchar2(30),dept_nonumber(5),dept_name
varchar2(10),date_of_join date);
Table created.
TABLE DESCRIPTION:
SQL> desc emp1978;
Name Null? Type
99 hari 79 IT 25-DEC-08
127 priya 89 ECE 11-SEP-09
129 lalitha 46 ECE 24-SEP-10
EMP_NO NUMBER(5)
EMP_NAME VARCHAR2(30)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE
SQL> alter table emp1977 add primary key(emp_no);Table
altered.
SQL> desc emp1977;
Name Null? Type
99 kamal 23 IT 29-SEP-07
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05
99 hari 79 IT 25-DEC-08
127 priya 89 ECE 11-SEP-09
129 lalitha 46 ECE 24-SEP-10
RESULT:
Thus, The table is created and Data Definition Commands, Data Manipulation Commands for Inserting,
Deleting, Updating And Retrieving Tables are successfully executed.
EX.NO:2
ADD FOREIGN KEY CONSTRAINTS AND INCORPORATE REFERENTIAL
INTEGRITY
DATE:
AIM :
To create table and Execute Data Definition Commands, Data Manipulation Commands to add foreign key constraints and
incorporate referential integrity Statements.
CREATION OF TABLE WITHOUT PRIMARY KEY:
SQL> create table emp1977(emp_no number(5),emp_name varchar2(30),dept_no
number(5),dept_name varchar2(10),date_of_join date);
Table created.
TABLE DESCRIPTION:
SQL> desc emp1977;
Name Null? Type
EMP_NO NUMBER(5)
EMP_NAME VARCHAR2(30)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE
CREATION OF TABLE WITH PRIMARY KEY:
SQL> create table emp1978(emp_no number(5) primary key,emp_name varchar2(30),dept_nonumber(5),dept_name
varchar2(10),date_of_join date);
Table created.
TABLE DESCRIPTION:
SQL> desc emp1978;
Name Null? Type
99 hari 79 IT 25-DEC-08
127 priya 89 ECE 11-SEP-09
129 lalitha 46 ECE 24-SEP-10
EMP_NO NUMBER(5)
EMP_NAME VARCHAR2(30)
DEPT_NO NUMBER(5)
DEPT_NAME VARCHAR2(10)
DATE_OF_JOIN DATE
SQL> alter table emp1977 add primary key(emp_no);Table
altered.
SQL> desc emp1977;
Name Null? Type
99 kamal 23 IT 29-SEP-07
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05
99 hari 79 IT 25-DEC-08
127 priya 89 ECE 11-SEP-09
129 lalitha 46 ECE 24-SEP-10
99 kamal 23 IT 29-SEP-07
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05
ADDING CONSTRAINTS TO TABLE:
SQL> alter table emp1978 add (salary number);Table
altered.
SQL> select *from emp1978;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J SALARY
99 kamal 23 IT 29-SEP-07
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05
SQL> update emp1978 set salary=3000 where emp_no=99;1 row
updated.
SQL> update emp1978 set salary=2000 where emp_no=127;1 row
updated.
SQL> update emp1978 set salary=1800 where emp_no=129;
1 row updated.
SQL> select *from emp1978;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME DATE_OF_J SALARY
99 kamal 23 IT 29-SEP-07
127 ravi 88 ECE 26-DEC-07
129 nirmal 90 ECE 16-JUN-05
RENAMING TABLE:
SQL> rename emp1978 to emp1979;Table
renamed.
TRUNCATION OF TABLE:
SQL> truncate table emp1979;Table
truncated.
SQL> select *from emp1979;no
rows selected DROPPING OF
TABLE:
SQL> drop table emp1979;
Table dropped.
CREATION OF TABLE:
SQL> create table emp1982(emp_no number(5)primary key,emp_name varchar2(20), dept_nonumber(5),dept_name
varchar2(20));
Table created.
SQL> create table emp1983(emp_no number(5)primary key,emp_name varchar2(20),dept_nonumber(5),dept_name
varchar2(20));
Table created.
DESCRIPTION OF TABLE:
SQL> desc emp1982;
Name Null? Type
SQL> rollback;
Rollback complete.
SQL> select *from emp1982;
EMP_NO EMP_NAME DEPT_NO DEPT_NAME
ARITHMETIC OPERATIONS:
SQL> select *from emp1982;
2104
SQL> select avg(emp_no) from emp1982;
AVG(EMP_NO)
701.333333
SQL> select max(emp_no) from emp1982;
MAX(EMP_NO)
991
SQL> select min(emp_no) from emp1982;
MIN(EMP_NO)
235
SQL> select count(emp_no) from emp1982;
COUNT(EMP_NO)
SET OPERATORS:
SQL> select *from emp1982;
SQL> select dept_no from emp1982 union select dept_no from emp1983;DEPT_NO
46
56
76
86
96
SQL> select dept_no from emp1982 union all select dept_no from emp1983;DEPT_NO
46
86
96
46
56
76
6 rows selected.
SQL> select dept_no from emp1982 intersect select dept_no from emp1983;DEPT_NO
46
SQL> select dept_no from emp1982 minus select dept_no from emp1983;DEPT_NO
86
96
RESULT:
Thus, The table is created and Data Definition Commands, Data Manipulation Commands for Inserting,
Deleting, Updating And Retrieving Tables and Transaction Control Statementsare successfully executed.
EX.NO:4
DATABASE QUERYING – SIMPLE QUERIES, NESTED QUERIES,SUB QUERIES
DATE: AND JOINS
AIM:
To Create Table and Apply Simple Queries Nested Queries, Sub Queries and Joins.
CREATION OF TABLE:
Table created.
created.
created.
created.
Table created.
created.
created.
SQL>alter table employee702 add foreign key(employee_no) references employee702 (employee_no)Table altered.
SUB QUERY:
1 row updated.
OUTER JOIN:
1 row created.
created.
created.
created.
Hari Pune
Om Mumbai
Smith Nashik
Jay Solapur
created.
created.
created.
created.
created.
Computer 8000
Hari Pune Computer 10000
Jay Solapur IT 5000
Om Mumbai IT 7000
ADDTIONAL QURIES:
Absolute
15
15.2
SquareRoot
Low
---
cse
MS.CAROL
3
SQL> select LTRIM('xxxXxxLAST','x') "LTRIM" from dual;
LTRIM
XxxLAST
TURNERX
********Page 1
CSE**
RESULT:
Thus, The Tables are created and Simple Queries , Nested Queries, Sub Queries and Joins areapplied on the
tables.
EX.NO:3 VIEWS, SEQUENCES, SYNONYMS
DATE:
AIM:
To create database and apply Views, Sequences, Synonyms.
TABLE CREATED:
desc book11;
BOOKNO NUMBER(10)
BOOK_NAME VARCHAR2(40)
TITLE VARCHAR2(40)
AUTHOR_NAME VARCHAR2(40)
altered.
BOOKNO NUMBER(10)
BOOK_NAME VARCHAR2(40)
TITLE VARCHAR2(40)
AUTHOR_NAME VARCHAR2(35)
SQL> /
SQL> /
Enter value for bookno: 3
Enter value for book_name: dbms
Enter value for title: DATABASE TECHNOLOGYEnter value
for author_name: SCHILLER
old 1: insert into book11 values(&bookno,'&book_name','&title','&author_name')
new 1: insert into book11 values(3,'dbms','DATABASE TECHNOLOGY','SCHILLER')1 row created.
SQL> /
SQL> /
1 C Programming in C BALAGURASWAMY
2 OOPS obj oriented programming BALAGURASWAMY
3 dbms DATABASE TECHNOLOGY SCHILLER
4 SW SOFTWARE ENGG PRESSMAN
5 mm MULTIMEDIA KAVITHA
CREATION OFVIEWS:
1 c Programming in C BALAGURASWAMY
2 OOPS obj oriented programming BALAGURASWAMY
3 dbms DATABASE TECHNOLOGY SCHILLER
4 SW SOFTWARE ENGG PRESSMAN
5 MM MULTIMEDIA KAVITHA
UPDATABLE VIEWS:
updated.
1 C Programming in C BALAGURASWAMY
2 OOPS obj oriented programming BALAGURASWAMY
3 dbms DATABASE TECHNOLOGY SCHILLER
4 SW SOFTWARE ENGG PRESSMAN
5 MM MULTIMEDIA KAVITHA
1 C Programming in C BALAGURASWAMY
2 OOPS obj oriented programming BALAGURASWAMY
3 dbms DATABASE TECHNOLOGY SCHILLER
4 SW SOFTWARE ENGG PRESSMAN
5 mm MULTIMEDIA KAVITHA
1 C Programming in C BALAGURASWAMY
2 OOPS obj oriented programming BALAGURASWAMY
DESTROYING A VIEW:
SEQUENCES:
Sequence is a set of integers 1, 2, 3, … that are generated and supported by some database systems toproduce unique
values on demand.
Example 1:
CREATE SEQUENCE sequence_1start
with 1
increment by 1
minvalue 0
maxvalue 100
cycle;
Above query will create a sequence named sequence_1.Sequence will start from 1 and will be incremented by 1
having maximum value 100. Sequence will repeat itself from start value afterexceeding 100.
Example 2:
Following is the sequence query creating sequence in descending order.
Above query will create a sequence named sequence_2.Sequence will start from 100 and should beless than or
equal to maximum value and will be incremented by -1 having minimum value 1.
into table
Output:
| ID | NAME |
| 1 | Ramesh |
| 2 | Suresh |
SYNONYMS:
This first CREATE SYNONYM example demonstrates how to create a synonym called suppliers.Now, users of other
schemas can reference the table called suppliers without having to prefix the table name with the schema named
app. For example:
If this synonym already existed and you wanted to redefine it, you could always use the ORREPLACE
phrase as follows:
Once a synonym has been created in Oracle, you might at some point need to drop the synonym.
This DROP statement would drop the synonym called suppliers that we defined earlier.
RESULT:
Thus a database is created and and Views, Sequences, Synonyms are applied on the table.
EX.NO: 8
TRIGGERS
DATE:
AIM:
Table created.
created.
created.
created.
BEFORE INSERT:
create or replace trigger vaijy before insert on emp901 for each rowdeclare
k integer;
begin
select count(*)into k from emp901;
if(k>=5)then
dbms_output.put_line('Add only Five record');end if;
end;
created.
created.
6 rows selected.
AFTER DELETE:
create or replace trigger vaily1 after delete on emp901 for each rowbegin
dbms_output.put_line('you are deleting the record');end;
SQL> set serveroutput on;
SQL> start mur13.sql;
5 /
Trigger created.
1 row deleted.
SQL> select * from emp901;
create or replace trigger vijay2 after update on emp901 for each rowbegin
dbms_output.put_line('Updated successfully in your database');end;
SQL> set serveroutput on;
SQL> start up15.sql;
5 /
Trigger created.
SQL> update emp901 set name='murali' where id=5;Updated
successfully in your database
1 row updated.
AFTER INSERT
Trigger created.
SQL> insert into emp905 values(6,'ravi',9000,5000,4000);Do not
enter more records
1 row created.
BEFORE DELETE:
SQL>edit bede.sql;
create or replace trigger ven4 before delete on emp905 for each rowbegin
dbms_output.put_line('Stop deleting records..');end;
SQL> set serveroutput on;
SQL> start bede.sql;
5 /
Trigger created.
1 row deleted.
ENABLING (OR) DISABLING TRIGGERS:
Trigger altered.
Trigger altered.
altered.
DROPPING TRIGGER:
Trigger dropped.
RESULT:
AIM:
To design a database using ER Modeling and implement Normalization for an Application.
AIM: To Relate the entities appropriately. Apply cardinalities for each relationship. Identify strongand weak entities.
Indicate the type of relationships (total/partial). Incorporate generalization, aggregation and specialization etc
wherever required.
E-R Model
Bus
BusNo
Source
Destination
CoachType
SCHEMA
Bus: Bus(BusNo :String ,Source : String, Destination: String, Coach Type: String)
Ticket
TicketNo
DOJ
Address
ContactNo
BusNo
Passenger
PassportID
TicketNo
Name
ContactNo
Age
Sex
Address
SCHEMA
Passenger (PassportID: String, TicketNo :string, Name: String, ContactNo: string, Age:integer, Sex: character,
Address: String)
Reservation
PNRNo
DOJ
No_of_seats
Address
ContactNo
BusNo
SeatNo
SCHEMA
Reservation(PNRNo: String, DOJ: Date, NoofSeats: integer , Address: String ,ContactNo: String, ,BusNo: String,SeatNo:Integer)
Cancellation
PNRNo
DOJ
SeatNo
ContactNo
Status
SCHEMA
Cancellation (PNRNo: String, DOJ: Date, SeatNo: integer, ContactNo: String, Status:String)
CONCEPT DESIGN WITH E-R MODEL
NORMALIZATION
AIM: Apply the database Normalization techniques for designing relational database tables tominimize duplication of
information like 1NF, 2NF, 3NF, BCNF.
1NF: A Relation scheme is said to be in 1NF if the attribute values in the relation areatomic.i.e., Mutli
–valued attributes are not permitted.
2NF: A Relation scheme is said to be in 2NF,iff and every Non-key attribute is fullyfunctionally
dependent on primary Key.
3NF: A Relation scheme is said to be in 3NF,iff and does not have transitivity dependencies.A Relation is
said to be 3NF if every determinant is a key for each & every functional dependency
BCNF: A Relation scheme is said to be BCNF if the following statements are true for eacg FDP->Q in set F
of FDs that holds for each FD. P->Q in set F of FD's that holds over R. Here P isthe subset of attributes of
R & Q is a single attribute of R.
P is a super key.
Normalized tables are:-
SQL> Create table Ticket2(TicketNo Integer Primary key,JourneyDate DateTime, Age Int(4),Sexchar(2),Source
varchar(20),Destination varchar(20),DeptTime varchar(2));
RESULT:
Thus a table is designed for a database using ER Modeling and Normalization isimplemented for
Passenger Application.
EX.NO:9A
DATABASE CONNECTIVITY WITH FRONT END TOOLS
DATE:
AIM :
EXECUTION:
FORM1
VB CODINGS:
Private Sub ADD_Click()
Dim a As Integer
a = Val(Text1.Text) + Val(Text2.Text)
MsgBox ("Addition of Two numbers is" + Str(a))End
Sub
VB CODINGS
RESULT:
SAMPLE OUTPUT:
Private Sub Command1_Click()
DataReport1.Show
End Sub
EX.NO:9B
DATABASE CONNECTIVITY WITH FRONT END TOOLS
DATE:
AIM:
To connect MS-ACCESS back end Database with Visual Basic Front end Tool.
Connect to databases created with Access 2000-2003 by using the following procedure.
4. Select Database on the Choose a Data Source Type page, and then select Next.
5. Select Dataset on the Choose a Database Model page, and then select Next.
6. On the Choose your Data Connection page, select New Connection to configure a newdata connection.
7. If the data source is not Microsoft Access Database File (OLE DB), select Change to openthe Change
Data Source dialog box and select Microsoft Access Database File, and then select OK.
8. In the Database file name, specify the path and name of the .mdb file you want to connectto, and then
select OK.
The dataset is added to your project, and the tables and views appear in the Data Sources
window.
Now the table from the MS Access database is now connected to the form designed.
ScreenShots:
Use the ADO Data Control to create a Connection
The first step in using the ADO Data Control to create a Connection to a database is to find the ADOData Control. By
default, the DAO Data Control is contained in the Visual Basic Toolbox, so you'll need to select Project- Components
from the Visual Basic Menu Bar, and select the Microsoft ActiveX Data Control…
If you click on the OK button, the ActiveX Data Control will then appear in the form.
RESULT :
Thus the database table in the MS-ACCESS is now connected to the Visual Basic 6.0successfully through ADO
Control.
CASE STUDY USING REAL LIFE DATABASE
EX.NO:10A
APPLICATIONS
AIM:
To develop a Payroll Processing System using Oracle as s back end(data base) and Microsoft Visualbasic as a front
end.
Table created.
ENO NUMBER
ENAME VARCHAR2(20)
DESIGNATION VARCHAR2(20)
SEX VARCHAR2(1)
AGE NUMBER
BASICSAL NUMBER(15,5)
DA NUMBER(15,5)
HRA NUMBER(15,5)
PF NUMBER(15,5)
SALARY NUMBER(15,5)
RESULT
A Payroll Processing System using Oracle as s back end(data base) and Microsoft Visual basicas a front
end is developed and executed successfully.
EX.NO:10B CASE STUDY USING REAL LIFE DATABASE
APPLICATIONSBANKING SYSTEM
DATE:
AIM:
To develop a Banking System using Oracle as s back end(data base) and Microsoft Visual basicas a front end.
Table created.
ACCNO NUMBER(10)
NAME VARCHAR2(25)
ADDRESS VARCHAR2(25)
BALANCE NUMBER(20)
1 row created.
SQL> /
Enter value for accno: 1002 Enter
value for name: kavi Enter value
for address: koil stEnter value for
balance: 2000
old 1: insert into bank82 values(&accno,'&name','&address',&balance)new 1: insert into
bank82 values(1002,'kavi','koil st',2000)
commit; Commit
complete.
SQL> select *from bank82;
VB CODINGS:
Thus a Banking System using Oracle as s back end(data base) and Microsoft Visual basic as afront end is
developed and executed successfully.