Professional Documents
Culture Documents
Experiment: 1
Aim: Hands on experience on any RDBMS to implement the role of Database
Administrator like creating the users, alter user, grant and revoke of rights of user.
THEORY:
SQL: It is structured query language, basically used to pass the query to retrieve and
manipulate the information from database. Depending upon the nature of query,
SQL is divided into different components:
• DDL(Data Definition Language )
• DML(Data Manipulation Language )
• DCL(Data Control Language )
DDL: The Data Definition Language (DDL) is used to create the database (i.e. tables, keys,
relationships etc), maintain the structure of the database and destroy databases and database
objects.
Table created.
SQL> DESC EMP1
Theory:
SELECT COMMAND:
TYPE 1:
SQL> select * from sub;
NAME AGE MARK1 MARK2 MARK3
-------- ---------- ---------- --------------- ------------
sachin 12 90 90 90
sachin 22 90 89 78
ranjan 21 89 78 80
gayathri 12 78 89 90
rajini 22 90 87 56
TYPE 2:
SQL> select name,age from sub;
NAME AGE
-------- ----------
sachin 12
sachin 22
ranjan 21
gayathri 12
rajini 22
TYPE 3:
NAME
--------
Gayathri
Rajini
Ranjan
Sachin
TYPE 4:
sachin 12 90 90 90
SQL> delete from sub where name='sachin';2 rows deleted.SQL> select * from sub;
ranjan 21 89 78 80
gayathri 12 78 89 90
rajini 22 90 87 56
TYPE 5:
NAME
--------
Gayathri
Rajin
Iranjan
TYPE 6:
NAME
Ranjan
Rajini
Gayathri
PROJECT COMMAND
CREATE COMMAND:
Table created.
DESC COMMAND:
NAME VARCHAR2(8)
AGE NUMBER(5)
MARK1 NUMBER(4)
MARK2 NUMBER(4)
MARK3 NUMBER(4)
ALTER COMMAND:
1)ADD COMMAND:
Table altered.
NAME VARCHAR2(8)
AGE NUMBER(5)
MARK1 NUMBER(4)
MARK2 NUMBER(4)
MARK3 NUMBER(4)
TOTAL NUMBER(6)
RENAME COMMAND:
Table renamed.
NAME VARCHAR2(8)
AGE NUMBER(5)
MARK1 NUMBER(4)
MODIFY COMMAND:
NAME VARCHAR2(8)
AGE NUMBER(5)
MARK1 NUMBER(4)
MARK2 NUMBER(4)
MARK3 NUMBER(6)
TOTAL NUMBER(4)
MARK3 NUMBER(6)
TOTAL NUMBER(6)
TRUNCATE COMMAND:
Table truncated.
JOINS:
SQL>selectemps1.ename,emps1.eno,customers1.eno,customers1.salary
fromemps1,customers1 where emps1.eno=customers1.eno;
SQL>
selectemps1.ename,emps1.eno,customers1.salary,customers1.eno,customers.locationfrom
emps1,customers1.eno<>customers1.eno;
SQL>select emps1.ename,emps1.eno,customers1.salary,customers1.eno
fromemps1,customers1
where emps1.eno(+)=customers1.eno;
where emps1.eno=customers1.eno(+);
ram 121
SET OPERATION
Table created.
SQL> insert into root values('&name','&age','&mark1','&mark2','&mark3');
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
SQL> /
1 row created.
sachin 12 89 89 90
kalai 20 90 90 78
rani 18 78 77 67
kalam 32 90 90 89
gokul 20 90 90 90
ranjan 21 89 78 80
gayathri 12 78 89 90
rajini 22 90 87 56
sachin 12 89 90 78
ram 21 90 67 78
UNION COMMAND:
SQL> select name,age from sub union select name,age from root;
NAME AGE
-------- ---------
gayathri 12
gokul 20
kalai 20
kalam 32
rajini 22
ram 21
rani 18
ranjan 21
sachin 129
rows selected.
SQL> select name,age from sub union all select name,age from root;
NAME AGE
-------- --------
ranjan 21
ayathri 12
rajini 22
sachin 12
ram 21
sachin 12
kalai 20
rani 18
kalam 32
gokul 20
10 rows selected.
INTERSECT:
SQL> select name from sub intersect select name from root;
NAME
--------
sachin
DIFFERENCE or MINUS:
SQL> select name from sub minus select name from root;
NAME
--------
Gayathri
Rajini
Ram
ranjan
Experiment: 4
Aim: Perform the following data manipulation operation on table created in Problem 2
(a) insertion of records
(b) deletion of records
(c) Updating records
Theory:
DML & DCL COMMANDS
SQL> create table sub (name varchar(8),age number(5),mark1 number(4),mark2 number(4),2
mark3 number(4));
Table created.
INSERT COMMAND:
TYPE 1:
SQL> insert into sub values('&name','&age','&mark1','&mark2','&mark3');
Enter value for name: Sachin
Enter value for age: 12
Enter value for mark1: 78
Enter value for mark2: 78
Enter value for mark3: 67
old 1: insert into sub values('&name','&age','&mark1','&mark2','&mark3')
new 1: insert into sub values('sachin','12','78','78','67')
1 row created.SQL> /
Enter value for name: ranjan
Enter value for age: 22
Enter value for mark1: 89
Enter value for mark2: 78
Enter value for mark3: 65
old 1: insert into sub values('&name','&age','&mark1','&mark2','&mark3')
new 1: insert into sub values('ranjan','22','89','78','65')
1 row created.
SQL> select * from sub;
NAME AGE MARK1 MARK2 MARK3
-------- ---------- ---------- ---------- ------------
sachin 12 78 78 67
ranjan 22 89 78 65
TYPE 2:
SQL> insert into sub(name,age,mark1,mark2,mark3) values ('ram',20,90,90,98);
1 row created.
SQL> select * from sub;
NAME AGE MARK1 MARK2 MARK3
-------- ---------- ---------- ---------- ----------
sachin 12 78 78 67
ranjan 22 89 78 65
ram 20 90 90 98
TYPE 3:
SQL> insert into sub values ('gayathri',13,90,100,98);
1 row created.
SQL> select * from sub;
NAME AGE MARK1 MARK2 MARK3
-------- ---------- ---------- ---------- ------------
sachin 12 78 78 67
ranjan 22 89 78 65
ram 20 90 90 98
gayathri 13 90 100 98
UPDATE COMMAND:
SQL> update sub set age=13 where name='ranjan';
1 row updated.
SQL> select * from sub;
NAME AGE MARK1 MARK2 MARK3
-------- ---------- ---------- ------------ ----------
sachin 12 78 78 67
ranjan 13 89 78 65
ram 20 90 90 98
gayathri 13 90 100 98
SQL> alter table sub add(total number(5));
Table altered.
SQL> select * from sub;
NAME AGE MARK1 MARK2 MARK3 TOTAL
-------- ---------- ---------- ---------- ---------- - -----------
sachin 12 78 78 67
ranjan 13 89 78 65
ram 20 90 90 98
gayathri 13 90 100 98
SQL> update sub set total=mark1+mark2+mark3;
4 rows updated.
SQL> select * from sub;
NAME AGE MARK1 MARK2 MARK3 TOTAL
-------- ---------- ---------- ---------- ---------- -----------
sachin 12 78 78 67 223
ranjan 13 89 78 65 232
ram 20 90 90 98 278
gayathri 13 90 100 98 288
SQL> select avg(mark1) from sub;
AVG(MARK1)
----------
86.75
SQL> select count(name) from sub;
COUNT(NAME)
-----------
4
SQL> select sum(mark2) from sub;
SUM(MARK2)
----------
346
DELETE COMMAND:
SQL> delete from sub where name='ram';
1 row deleted.
SQL> select * from sub;
NAME AGE MARK1 MARK2 MARK3 TOTAL
-------- ---------- ---------- ---------- -------- -----------
sachin 12 78 78 67 223
ranjan 13 89 78 65 232
gayathri 13 90 100 98 288
SQL> delete from sub;
3 rows deleted.
SQL> select * from sub;
no rows selected
Experiment: 5
Aim- Creation and modification of databases through ER diagram, nornmalisation Creation,
updation, insertion and deletion of tables.
THEORY:
• Database :
A Database is a collection of interrelated data and a Database Management
System is a a software system that enables users to define, create and maintain the database
and which provides controlled access to the database.
• ER- Diagram :
It is an Entity –Relationship diagram which is used to represent the
relationship between different entities. An entity is an object in the real world which is
distinguishable from other objects. The overall logical structure of a database can be
expressed graphically by an ER diagram, which is built up from following components.
Rectangles: represent entity sets.
Ellipses: represent attributes.
Diamonds: represent relationships among entity sets.
Lines: link attribute to entity sets and entity sets to relationships.
• Mapping Cardinalities :
It expresses the number of entities to which another entity can be associated via a
relationship set. For a binary relationship set R between entity sets A and B.
The Mapping Cardinalities must be one of the following.
• One to one
• One to many
• Many to one
• Many to many
Conversion from ER diagram to tables
Step 1: Mapping of Regular Entity Types:
For each regular(strong) entity type E in the ER schema create a relation R that
includes all the simple attributes of E. Include only the simple component attributes of a
composite ,the set of simple attributes that form it will together form the primary key of R.
Step 2: Mapping of Weak Entity Types:
3
For each weak entity type W in the ER schema with owner entity type E, create a
relation R and include all the attributes of W and the specific attributes of R. In addition
include the Primary key attribute(s) of the owner entity type. The primary key of R is the
combination of the primary key(s) of the owner(s) and the partial key of the Weak Entity
Type W.
Step 3 : Mapping of Binary 1:1 Relationship Types :
For each binary 1:1 relationship type R in the ER schema, identify the relations S
and T that correspond to the Entity Types participating in R. Choose one of the relations- S,
say – and include as a Foreign key in S the primary key of T. It is better to choose an entity
type with total participation in R in the role of S. Include all the simple attributes (or simple
components of a composite attributes) of the 1:1 relationship type R as attributes of S.
Step 4: Mapping of Binary 1:N Relationship Types :
For each regular binary 1:N relationship type R, identifying the relation S that
represent the participating Entity Type at the N side of the relationship type. Include as
Foreign key in S the primary key of T that represents the other entity type participating in R;
this is done because each entity instance on the N side is related to at most one entity instance
on the 1-side of the relationship Type. Include any simple attributes (or simple components
of composite attributes) of the 1:N relationship type as attributes of S.
Step 5: Mapping of Binary M:N Relationship Types :
For each binary M:N relationship type R, create a new relation S to represent R.
Include the primary key of the participating entity types; their combination will form the
primary key of S. Also include any simple attributes of the M:N relationship types (or
simple components of a composite attributes) as attributes of S.
Step 6: Mapping of Multivalued Attributes:
For each Multivalued Attribute A, create a new relation R. This relation R will
include an attribute corresponding to A, plus the primary key attribute K- of the relation that
represents the entity type or relationship type that has A as an attribute. The primary key of R
is the combination of A and K. If the multivalued attribute is composite, we include its
simple components.
Step 7: Mapping of N-ary Relationship Types:
For each N-ary relationship type R, where N>2, create a new relation S to represent
R. Include the primary keys of the relations that represent the participating entity types. Also
include any simple attributes of the N-ary relationship types (or simple components of a
composite attributes) as attributes of S.
Conclusion:
Referring to the problem statement the ER diagram was designed and converted into
the tables.