0% found this document useful (0 votes)
4 views

Dbms Lab Manual

The document outlines various SQL commands for database creation, manipulation, and management, including data definition and data manipulation commands. It details the steps for creating tables, altering them, inserting, updating, and deleting records, as well as implementing foreign key constraints and referential integrity. Additionally, it covers querying techniques such as joins, subqueries, and aggregate functions to retrieve and manipulate data effectively.

Uploaded by

vigneshs042006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Dbms Lab Manual

The document outlines various SQL commands for database creation, manipulation, and management, including data definition and data manipulation commands. It details the steps for creating tables, altering them, inserting, updating, and deleting records, as well as implementing foreign key constraints and referential integrity. Additionally, it covers querying techniques such as joins, subqueries, and aggregate functions to retrieve and manipulate data effectively.

Uploaded by

vigneshs042006
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

EX.

NO:1a DATA DEFINITION COMMANDS


DATE:

AIM:
To implement database creation and do the operations in database using Data Definition
Commands

ALGORITHM:
Step 1: Create table by using create table command with column name, data type and size.
Step 2: Display the table by using desc command.
Step 3: Add any new column with the existing table by alter table command.
Step 4: Modify the existing table with modify command.
Step 5: Delete the records in files by truncate command.
Step 6: Delete the Entire table by drop command.

1) CREATE TABLE

Syntax:

create table table_name( column1 datatype, column2 datatype,


column3 datatype,..... columnN datatype);

Example:

create table employee(id int,name varchar(100),age int,address varchar(100),salary float);

Table employee created

2) DESCRIBING THE TABLE

Syntax:
desc table_name;

Example:
desc employee;

3) ALTER TABLE

Syntax:
alter table table_name add column_name datatype;

Example:
alter table employee add dept varchar(10);
table employee altered

select * from employee;

Example:
alter table employee add (state varchar(100),weight float);
table employee altered.

select * from employee;

table employee altered.

4) RENAME
To rename column name
Syntax:
alter table table_name rename column existing _name to new_name;

Example:
alter table employee rename column address to addr;
table employee altered.

select * from employee

To rename table name


Syntax:
alter table table_name rename to new_table_name;

Example:
alter table employee rename to empl;
table employee altered.

select * from employee;


ORA-00942: table or view does not exist
00942. 00000 - "table or view does not exist"
*Cause:
*Action:
Error at Line: 21 Column: 15
select * from empl;

5) TRUNCATE

Syntax:
truncate table table_name;

Example:
truncate table emp;
select * from empl;

no data found

6) DROP TABLE

Syntax:
drop table table_name;

Example:

drop table empl;


table customers dropped.

select * from empl;


ORA-00942: table or view does not exist

PERFORMANCE 25

VIVA 10
RECORD 15
TOTAL 50

RESULT:
Thus the queries to implement data definition commands are executed successfully.
EX.NO:1b DATA MANIPULATION COMMANDS
DATE:

AIM:
To implement and execute a query for manipulating & storing data items in a Oracle
database using Structured Query Language commands

ALGORITHM:
Step 1: Create table by using create table command.
Step 2: Insert values into the table
Step 3: Delete any records from the table
Step 4: Update any values in the table.
Step 5: Display the values from the table by using select command.

1) CREATE A TABLE

create table student(id int,Name varchar(30),Department varchar(10));

desc student;

2) INSERT
Syntax:
insert into table_name values(column1,column2,….);
Example:
insert into student values(1,'ABC','CSE');
insert into student values(2,'DEF','CSE');
select * from student;

To insert NULL values to column:


The following syntax is used to insert NULL value to the column.

insert into student values(3,'null','CSE');


select * from student;
To insert default value to the column:
The following syntax is used to insert default value to the table.
Syntax:
insert into table_name values(column1,column2,…);

Example:
insert into student values(3,’alex’,default);
1 rows inserted.
select * from student;

To insert data using select statement:


The following syntax is used insert all the values from another table using select statement.
Syntax:
insert into table_name1 select * from table_name2;

Example:
create table stud(id int,Name varchar(30),Department varchar(10));
insert into stud select * from student;

3) UPDATE
Syntax:
update table_name set column1 = value1, column2 = value2. .. , columnn = valuen
where [condition];
Example: (single column)

update stud set Department='ECE' where id=3;


1 rows updated.
Example: (multiple column)

update stud set Name=’XYZ’,Department='CIVIL' where id=2;

4) DELETE

Syntax: (delete particular row)


delete from table_name where condition;

Example:
delete from stud where id=2;

Syntax:
delete from table_name;

Example:
delete from stud;
select * from stud;

no data found

PERFORMANCE 25
VIVA 10
RECORD 15
TOTAL 50

RESULT:
Thus, a query for manipulating & storing data items in an Oracle database using
Structured Query Language commands were implemented and executed successfully.
EX.NO:2 CREATE SET OF TABLES ADD FOREIGN KEY CONSTRAINT AND
DATE: INCORPORATE REFERENTIAL INTEGRITY

Aim:
To create set of tables add foreign key constraint and incorporate referential integrity using SQL.

Algorithm:
 Create two tables with a link that will not work.
 Create two tables with a link that will work.
 Add a foreign key to enforce referential integrity between the two tables.
 Delete data from the tables.
 Update and remove data to show how the foreign key protects the data.
 Use the cascade option of the foreign key.
 Companies table: List of Companies
 Employees table: List of Employees working at the Company
 Rule: Employees can only work at one Company, and a Company can employ multiple
Employees

Program:
Step 1:
--Create the HRDatabase
USE master
GO
DROP DATABASE IF EXISTS HRDatabase
GO
CREATE DATABASE HRDatabase
GO
USE HRDatabase
GO
Step 2:
-1st Try: Create a Companies and an Employees table and link them together
DROP TABLE IF EXISTS Companies;
GO
DROP TABLE IF EXISTS Employees;
GO
-- SQL CREATE TABLE Statement
CREATE TABLE Companies (
ID INT CONSTRAINT PK_Companies PRIMARY KEY IDENTITY,
CompanyName VARCHAR(80) NOT NULL, -- column name, data types and null value
CompAddress VARCHAR(80) NOT NULL,
CompContactNo VARCHAR(20) NOT NULL,
EmpID INT NOT NULL,
CreateDate DATETIME NOT NULL constraint DF_Companies_CreateDate DEFAULT
getdate()
)CREATE TABLE Employees (
ID INT CONSTRAINT PK_Employees PRIMARY KEY IDENTITY,
EmployeeName VARCHAR(80) NOT NULL,
ContactNo VARCHAR(20) NOT NULL,
Email VARCHAR(80) NOT NULL,
CreateDate DATETIME NOT NULL constraint DF_Employees_CreateDate DEFAULT
getdate()
)
INSERT INTO Companies (CompanyName, CompAddress, CompContactNo, EmpID)
VALUES
('Alpha Company', '123 North Street, Garsfontein, Pretoria', '091 523 6987' , 1),
('Bravo Company', '456 South Street, Brooklyn, Pretoria', '091 523 4789' , 1),
('Charlie Company' , '987 West Street, Lynnwood, Pretoria', '091 523 1235' , 1),
('Delta Company', '258 East Street, The Meadows, Pretoria', '091 523 7414' , 1),
('Echo Company', '100 Amber Street, Hatfield, Pretoria', '091 523 9685' , 1)
INSERT INTO Employees (EmployeeName, ContactNo, Email) VALUES
('Joe Blogs' , '012 365 4789', '[email protected]') ,
('Jane Doe' , '012 365 4789', '[email protected]') ,
('John Smit' , '012 365 4789', '[email protected]') ,
('Eddy Jones' , '012 365 4789', '[email protected]'),
('Steve Dobson', '012 365 4789', '[email protected]')

SELECT * FROM Companies


SELECT * FROM Employees

OUTPUT :
3

PERFORMANCE 25

VIVA 10
RECORD 15
TOTAL 50

RESULT:
Thus, to create a set of tables add foreign key constraint and incorporate referential integrity were
implemented and executed successfully.
Ex: no: 3 DATABASE TABLES WITH DIFFERENT
Date: 'WHERE CLAUSE' CONDITIONS

Aim:
To using query the database tables with different 'where clause' conditions also implement aggregate
Function with algorithm.

Algorithm:

Step 1:
There are tables country and city. We’ll use the following statements:

SELECT *
FROM country;
SELECT *
FROM city;
You can see the result in the picture below:

Step 2:
SELECT *
FROM country
INNER JOIN city ON city.country_id = country.id;

SELECT COUNT(*) AS number_of_rows


FROM country
INNER JOIN city ON city.country_id = country.id;
Step 3:

SELECT *
FROM country
LEFT JOIN city ON city.country_id = country.id;

SELECT COUNT(*) AS number_of_rows


FROM country
LEFT JOIN city ON city.country_id = country.id;

SELECT COUNT(country.country_name) AS countries, COUNT(city.city_name) AS cities


FROM country
LEFT JOIN city ON city.country_id = country.id;

PERFORMANCE 25

VIVA 10
RECORD 15
TOTAL 50

RESULT:
Thus, to create the database tables with different 'where clause' conditions and also implement
aggregate Function with algorithm were implemented and executed successfully.
EX.NO:4 SIMPLE QUERIES, SUB QUERIES and JOINS
DATE:

AIM:
To implement Simple queries, Nested queries, Sub queries using structured query
language

ALGORITHM:

STEP 1: Create a table with the columns that are needed


STEP 2: Write simple queries to insert, delete, update and implement some functions
STEP 3: Write nested queries using clauses to retrieve data from the table
STEP 4: The nested queries may have more than one sub queries.
STEP 5: Efficiently retrieve data from the table

QUERIES:
create table salary(id int, Name varchar(20),Age int,Salary float);
insert into salary values(1,'Ajay',25,20000);
insert into salary values(2,'Archana',28,30000);
insert into salary values(3,'Archana',23,25000);
insert into salary values(4,'Sara',24,20000);
insert into salary values(5,'Ajay',25,40000);
insert into salary values(6,'Srinithi',26,35000);
select * from salary;

Sum function
Syntax:
select column_name1,sum(column_name2)from table_name group by column_name3;

Example:
select name, sum(salary) from salary group by name;

Min function

Syntax:
select column_name1,min(column_name2)from table_name group by column_name3;

Example:
select name, min(salary) from salary group by name;

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


Max function
Syntax:
select column_name1,max(column_name2)from table_name group by column_name3;
Example:
select name, max(salary) from salary group by name;

Count function

Syntax:
select column_name1,count(column_name2)from table_name group by column_name3;
Example:
select name, count(salary) from salary group by name;

Mod function

Syntax:
select column_name1,mod(column_name2)from table_name;
Example:
select name,mod(salary,5) from salary;

DISTINCT and ORDER BY Clause

Syntax:
select distinct column1, column2,. ... columnn from table_name;

Example:
select salary from salary order by salary;

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


select distinct salary from salary order by salary;

HAVING clause
Example:

select min(salary)from salary group by age having max(salary)<30000;

Select using Conditions

AND
Example:
select * from salary where age >= 25 and salary >= 25000;

OR
Example:
select * from salary where age >= 25 or salary >= 25000;

LIKE
select * from salary where name like 'Aj%';

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


IN
select * from salary where age in ( 25, 28 );

BETWEEN

select * from salary where salary between 20000 and 30000;

IS NOT NULL

select * from salary where age is not null;

IS NULL

select * from salary where age is null;


no data found

(4,'Kumaran',25,'CBE',24000);

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


Subqueries with the INSERT Statement

INSERT INTO customers_backup


SELECT * FROM CUSTOMERS
WHERE ID IN
(SELECT ID
FROM CUSTOMERS) ;
4 rows inserted

select * from customers_backup;

Subqueries with the UPDATE Statement

UPDATE CUSTOMERS
SET SALARY = SALARY * 0.25
WHERE AGE IN
(SELECT AGE FROM customers_backup
WHERE AGE >= 27 );
Select * from customers;

Subqueries with the DELETE Statement

DELETE FROM CUSTOMERS


WHERE AGE IN
(SELECT AGE FROM CUSTOMERS_backup
WHERE AGE >= 27 );

select * from customers;

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


select age from customers where exists (select age from salary where salary > 25000);

JOINS

CREATE and INSERT values in TABLE(cust)

create table cust(id int primary key,name varchar(20),age int);


insert into cust values(1,'aaa',32);
insert into cust values(2,'aba',32);
insert into cust values(3,'abc',32);
insert into cust values(4,'ccc',25);
select * from cust;

CREATE and INSERT values in TABLE(order1)

create table order1(oid int primary key,custid int,amount int);


insert into order1 values(101,1,1000);
insert into order1 values(102,2,2000);
insert into order1 values(103,3,3000);

1. INNER JOIN

Syntax:
SELECT table1.column1, table2.column2...
FROM table1
INNER JOIN table2
ON table1.common_filed = table2.common_field;
Example:

select id,name,oid,amount

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


from cust
inner join order1
on cust.id=order1.custid;

2. LEFT JOIN:
Syntax:

select table1.column1, table2.column2...


from table1
left join table2
on table1.common_filed = table2.common_field;

Example:
select id,name,oid,amount
from cust
left join order1
on cust.id=order1.custid;

3. RIGHT JOIN:
Syntax:
select table1.column1, table2.column2...
from table1
right join table2
on table1.common_filed = table2.common_field;

Example:
select id,name,oid,amount
from cust
right join order1
on cust.id=order1.custid;

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


4. FULL JOIN:
Syntax:

select table1.column1, table2.column2...


from table1
full join table2
on table1.common_filed = table2.common_field;

Example:
select id,name,oid,amount
from cust
full join order1
on cust.id=order1.custid;

PERFORMANCE 25

VIVA 10
RECORD 15
TOTAL 50

RESULT:
Thus, the SQL commands to execute simple queries, sub queries and joins are
executed successfully.

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


EX.NO:5 NATURAL, EQUI AND OUTER JOIN
DATE:

Aim
To write DQL Commands to join, Restrict and Retrieve information from one or more
tables execute it and verify the same.

Selecting Rows with Equijoin using table Aliases

1. Write a query to display empid,name,deptid,deptname and


location for allemployees and verify it.

SQL> select
employee.empid,employee.name,employee.depid,department.deptname,depa
rtment.location from employee,department where
employee.depid=department.depid;

EMPID NAME DEPID DEPTNAME LOCATION

a123 ragu CS000 COMPUTER_SCIENCE CHENNAI


a124 rama CS000 COMPUTER_SCIENCE CHENNAI
a125 ram EE000 ELECT_ELECTRO MUMBAI
a128 sag EE000 ELECT_ELECTRO MUMBAI
c128 dinesh EC000 ELECT_COMM DELHI
d124 abc EC000 ELECT_COMM DELHI

6 rows selected.

2. Write a query to display the “dinesh” depid and deptname and verify it.
SQL> select e.empid,e.name,e.depid,d.deptname from employee
e,department d wheree.depid=d.depid and e.name='dinesh';

EMPID NAME DEPID DEPTNAME

c128 dinesh EC000 ELECT_COMM

Selecting Rows with Non-Equijoin using table Aliases:


[Other Conditions such as >=, <= and BETWEEN, AND ]

1. Write a query to display the name,salary and deptname of all


employees whose salary is greater than 10000 and verify it.

SQL> select e.name,e.salary,d.deptname from employee e,department d where


e.salary>10000and e.depid=d.depid;

NAME SALARY DEPTNAME

ragu 200000 COMPUTER_SCIENCE


rama 200000 COMPUTER_SCIENCE
ram 30000 ELECT_ELECTRO

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


Selecting Rows using Outer Joins:
[ Left Outerjoin,Right Outerjoin using ”+” symbol ]

1. Write a query to display the name, depid and deptname of all


employees. Make sure that employees without department are included
aswell and verify it.

SQL> select e.name,e.depid,d.deptname from employee e,department d where e.depid


=d.depid(+);

NAME DEPID DEPTNAME

rama CS000 COMPUTER_SCIENCE


ragu CS000 COMPUTER_SCIENCE
sag EE000 ELECT_ELECTRO
ram EE000 ELECT_ELECTRO
abc EC000 ELECT_COMM
dinesh EC000 ELECT_COMM
www

7 rows selected.
2. Write a query to display the name, salary,depid and deptname of
all employees. Make sure that departments without employees are
included as well and verify.
SQL> select e.name,e.salary,e.depid,d.deptname from employee
e,department d where e.depid(+)=d.depid;

NAME SALARY DEPID DEPTNAME

ragu 200000 CS000 COMPUTER_SCIENCE


rama 200000 CS000 COMPUTER_SCIENCE
ram 30000 EE000 ELECT_ELECTRO
sag 10000 EE000 ELECT_ELECTRO
dinesh 10000 EC000 ELECT_COMM
abc 5000 EC000 ELECT_COMM
MECHANICAL
CHEMICAL
8 rows selecte d

PERFORMANCE 25

VIVA 10
RECORD 15
TOTAL 50

RESULT:
Thus the SQL commands to execute natural, equi and outer joins are executed successfully.

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


EX.NO:6 PROCEDURES AND FUNCTIONS
DATE:

AIM:
To implement and execute Procedures in Oracle Database using Procedural Language
concepts.

PROCEDURES:
1) Procedure is a sub program used to perform an action.
2) Replace-recreates the procedure if it already exists.

3 MODES:
1) IN – Means you must specify a value for the argument at the time execution of the procedure.

2) OUT-passes back a value to its calling program.

3) INOUT – When calling the procedure, yu must specify the value and that procedures passes value back
to the calling procedure

CREATING A PROCEDURE

SYNTAX:

CREATE [OR REPLACE] PROCEDURE procedure_name


[(column_name [IN | OUT | IN OUT] type [, ...])]
{IS | AS}
BEGIN
< procedure_body >
END procedure_name;

CREATE OR REPLACE PROCEDURE greetings


AS
BEGIN
dbms_output.put_line('Hello World!');
END;

To run this procedure

BEGIN
greetings;
END;

DELETING A PROCEDURE

SYNTAX:

DROP PROCEDURE procedure-name;

EXAMPLE:

DROP PROCEDURE greetings;

Procedure dropped

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


EXAMPLE 2

Create a table user1

create table user1(id number(10) primary key,name varchar2(100));

Create the procedure

create or replace procedure


INSERTUSER(id IN NUMBER, name IN VARCHAR2)
is
begin
insert into user1 values(id,name);
end;

To execute the procedure

BEGIN
INSERTUSER(101,'Rahul');
dbms_output.put_line('record inserted successfully');
END;

PL/SQL FUNCTIONS

SYNTAX:

CREATE [OR REPLACE] FUNCTION function_name [parameters]


[(parameter_name [IN | OUT | IN OUT] type [, ...])]
RETURN return_datatype
{IS | AS}
BEGIN
< function_body >
END [function_name];

create or replace function adder(n1 in number, n2 in number)


return number
is
n3 number(8);
begin
n3 :=n1+n2;
return n3;
end;

EXECUTE THE FUNCTION

DECLARE
n3 number(2);
BEGIN
n3 := adder(11,22);
dbms_output.put_line('Addition is: ' || n3);
END;

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


Output:

Addition is: 33

Statement processed.

PERFORMANCE 25

VIVA 10
RECORD 15
TOTAL 50

RESULT:
Thus the PL/SQL procedures and functions are executed successfully

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


EX.NO.7 TRANSACTION CONTROL AND DATA CONTROL STATEMENTS
DATE:

AIM:
To implement Transaction Control statements using structured Query Language

ALGORITHM:

Step 1: Create table by using create table command.


Step 2: Insert values into the table
Step 3: Commit the table
Step 4: Insert or Update any values in the table.
Step 5: Rollback the table
Step 6: Insert or Update any values in the table.
Step 7: Fix a save point
Step 8: Repeat step 6 and 7
Step 9: Rollback to any save point

1) CREATE A TABLE

create table employeepersonaldetails(id int primary key,name varchar(30) not null,age int not
null,mobilenumber int not null unique);

insert into employeepersonaldetails values(1,'Ajay',20,9876543210);


insert into employeepersonaldetails values(2,'Brindha',20,9874563210);
insert into employeepersonaldetails values(3,'Kumaran',20,9673443210);
select * from employeepersonaldetails;

commit;

Statement executed

insert into employeepersonaldetails values(4,'Archana',20,9876543410);

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


rollback;

insert into employeepersonaldetails values(5,'Braham',20,9878953210);

savepoint a;

savepoint created

insert into employeepersonaldetails values(6,'Srimathi',20,9678953210);

savepoint b;

rollback to a;

PERFORMANCE 25

VIVA 10
RECORD 15
TOTAL 50

RESULT:
Thus Transaction Control and Data Control statements using structured Query Language is
executed successfully.

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


EX.NO:8 TRIGGERS
DATE:

AIM:
To implement PL/SQL triggers and do the operations in database automatically.

ALGORITHM:

STEP1: Create a table emply101


STEP2: Insert values into the table
STEP3: Create another table emply102
STEP4: Create trigger
CREATE OR REPLACE TRIGGER <TRIGGER NAME>
{BEFORE/AFTER/INSTEAD OF}
{INSERT/UPDATE/DELETE}
ON <TABLENAME/VIEWNAME>
REFRENCECING {OLD AS OLD /NEW AS NEW}
[FOR EACH STATEMENT /FOR EACH ROW [WHEN <CONDITION>]]
STEP5: Insert and delete record into emply101
STEP6: View the updations in emply102

CREATE TABLE emply101


create table emply101(eid varchar(20),ename char(25), age number(10), salary number(10));
insert into emply101 values(1,'abi',23,25000);
insert into emply101 values(2,'abinaya',22,20000);
insert into emply101 values(3,'abishek',23,25000);
select * from emply101;

CREATE TABLE emply102


create table emply102(eid varchar(20),ename char(25),age number(10),salary number(10));
select * from emply102;
no data found
Creating trigger
create or replace trigger tfg1 before insert on emply101 for each row
begin
insert into emply102 values(:new.eid,:new.ename,:new.age,:new.salary);
end;

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


Insert values into emply101

insert into emply101 values(4,'bala',23,25000);


select * from emply101;

select * from emply102;

CREATING TRIGGER FOR UPDATING AND DELETING

create or replace trigger trgrr15 after delete or update on emply101 for each row
begin
if deleting then
insert into emply102 values(:old.eid,:old.ename,:old.age,:old.salary);
elsif updating then
insert into emply102 values(:old.eid,:old.ename,:old.age,:old.salary);
end if;
end;

Update a value in emply101

update emply101 set salary=10000 where eid=1;


select * from emply102;

PERFORMANCE 25

VIVA 10
RECORD 15
TOTAL 50

RESULT:
Thus the SQL triggers are executed successfully and the output was verified successfully.

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


EX.NO:9 VIEWS AND INDEX
DATE:
AIM:

To write a DDL command to create views to restrict data access from one or more tables,execute
it and verify the same.

Creating views:

1. Create a view that contains employee id as “ID_NUMBER”, employee name


as “NAME”and salary as ”SALARY” for each employee in department 90.

SQL> create view vw_emp80(id,name,salary) as select empid,name,salary from


employee wheredeptid=90;

OUTPUT:
View created.

SQL> select * from vw_emp80;

ID NAME SALARY

s203 vidhya 29000

2. To create a view to set the salary Rs.15000/- to the employee id ‘a102’ in the
vw_dept_salary and verify the result in vw_emp12_sal and employees table.
SQL> update vw_emp12 set salary=15000 where

empid='a102';1 row updated.

To Verify: SQL> select * from vw_emp12;

SNO NAME SALARY DESIG LAST EMPID DEPTID HIRE_DATE

1 monica 15000 rep a a102 102 13-MAR-08


Creating Index
Create table
CREATE TABLE Colleges ( college_id INT PRIMARY KEY,college_code
VARCHAR(20),NOT NULL college_name VARCHAR(50)
);
create index
CREATE INDEX college_index ON Colleges(college_code);
Colleges
college_id college_code college PERFORMANCE 25
_name VIVA 10
Empty
RECORD 15
TOTAL 50
RESULT:

Thus the PL/SQL program for implementing views and index has been successfully executed.

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


EX.NO:10 XML SCHEMA
DATE:

AIM:

To implement XML Database and validate it using XML Schema.

PROGRAM :
CREATE TABLE t1
(id NUMBER,
xml XMLTYPE;

INSERT INTO t1 VALUES (1, '<?xml version="1.0" encoding="UTF-8"?>


<shiporder orderid="889923">
<orderperson>John Smith</orderperson>
<shipto>
<name>Ola Nordmann</name>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>');

INSERT INTO t1 VALUES (2, '<?xml version="1.0" encoding="UTF-8"?>


<shiporder orderid="889923">
<orderperson>John Smith</orderperson>
<shipto>
<name1>Ola Nordmann</name1>
<address>Langgt 23</address>
<city>4000 Stavanger</city>
<country>Norway</country>
</shipto>
<item>
<title>Empire Burlesque</title>
<note>Special Edition</note>
<quantity>1</quantity>
<price>10.90</price>
</item>
<item>
<title>Hide your heart</title>
<quantity>1</quantity>
<price>9.90</price>
</item>
</shiporder>');

COMMIT;

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


OUTPUT

SELECT id,
XMLISVALID(xml, 'my_schema.xsd') AS is_valid
FROM t1;

ID IS_VALID
1 1
2 0

PERFORMANCE 25

VIVA 10
RECORD 15
TOTAL 50

RESULT:
Thus the XML Database and validate it using XML Schema is executed successfully.

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


EX.NO:11 NOSQL DATABASE TOOLS
DATE

Aim:
To Create a Document, column and graph based data using NOSQL database tools.
Algorithm:
Step 1:
There are tables country and city. We’ll use the following statements:
SELECT * FROM country;
SELECT *FROM city;
You can see the result in the picture below:

Step 2:
SELECT *FROM country
INNER JOIN city ON city.country_id = country.id;
SELECT COUNT(*) AS number_of_rows
FROM country
INNER JOIN city ON city.country_id = country.id;

Step 3:

SELECT *FROM country


LEFT JOIN city ON city.country_id = country.id;

SELECT COUNT(*) AS number_of_rows FROM country


LEFT JOIN city ON city.country_id = country.id;

SELECT COUNT(country.country_name) AS countries, COUNT(city.city_name) AS cities


FROM country
LEFT JOIN city ON city.country_id = country.id;
Aggregate Functions:

Create one Document:


db.collection.insertOne(
<document>,
{
writeConcern: <document>
Create Many Documents:
db.collection.insertMany(
[ <document 1> , <document 2>, ... ],
{
writeConcern: <document>,
ordered: <boolean>
}
)
Create Column:
1 Access the NoSQL console from the Infrastructure Console. See Accessing the Service from the Infrastructure
Console .
2. The NoSQL console lists all the tables in the tenancy. To view table details, do either of the following:
Click the table name, or
Click the action menu corresponding to the table name and select View Details.
The Table Details page opens up.
3. In the Table Details page, select the Columns tab under Resources.
You will see a list of all the columns added to the table.
4. Click Add Columns.

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


5. In the Add Columns window, select Simple Input for Table Column Update Mode.

Creating a GUI using Java:


Creating a Graphical User Interface
public class FeedReader extends JFrame {
// body of class
}
public class Payroll extends JFrame {
public Payroll() {
super("Edit Payroll");
setSize(300, 100);
setVisible(true);
}
}
setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
UIManager.setLookAndFeel(
"javax.swing.plaf.nimbus.NimbusLookAndFeel"
);
Developing a Framework

package com.java21days;

import javax.swing.*;

public class SimpleFrame extends JFrame {


public SimpleFrame() {
super("Frame Title");
setSize(300, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
}
private static void setLookAndFeel() {
try {
UIManager.setLookAndFeel(
"javax.swing.plaf.nimbus.NimbusLookAndFeel"
);
} catch (Exception exc) {
// ignore error
}
}
public static void main(String[] arguments) {
setLookAndFeel();
SimpleFrame sf = new SimpleFrame();
}
}
The output will be:

Creating a Component
JButton play = new JButton("Play");
JButton stop = new JButton("Stop");
JButton rewind = new JButton("Rewind");
Adding Components to a Container
J Button quit = new JButton("Quit");

JPanel panel = new JPanel();


panel.add(quit);

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


: package com.java21days;

import javax.swing.*;

public class

ButtonFrame extends

JFrame {JButton load =

new JButton("Load");

JButton save = new

JButton("Save");

JButton unsubscribe = new JButton("Unsubscribe");

public ButtonFrame() {
super("Button Frame");
setSize(340, 170);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.add(load);
pane.add(save);
pane.add(unsubscribe);
add(pane);
setVisible(true);
}

private static void setLookAndFeel() {


try {
UIManager.setLookAndFeel(
"javax.swing.plaf.nimbus.NimbusLookAndFeel"
);
} catch (Exception exc) {
System.out.println(exc.getMessage());
}
}

public static void main(String[] arguments) {


setLookAndFeel();
ButtonFrame bf = new ButtonFrame();
}
}

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


Output:

PERFORMANCE 25

VIVA 10
RECORD 15
TOTAL 50

RESULT
Thus the real life database application for exam registration has been successfully executed.

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


EX.NO:12 GUI BASED DATABASE APPLICATIONS
DATE:

AIM:
To implement an online exam registration page with database connectivity using php

ALGORITHM:

STEP 1: Develop a webpage which includes all the fields for registering for an online exam
STEP 2: Develop a PHP page which receives the values that are given as an input in the registration
pageSTEP 3: Connect the registration page with the PHP page
STEP 4: Receive the values from registration
pageSTEP 5: Establish a connection with the
database STEP 6: Store the received values in
the database

PROGRAM:

Registration.html

<html>
<body bgcolor="lightblue">
<p><center>REGISTRATION FORM</center></p>
<form action="Registration.php" method="post">
<center><pre><b> Student name: <input type="text" name="n" value="
"> Register Number: <input type="text" name="reg"
value=" ">
CGPA: <input type="text" name="cgpa"
value=" ">YEAR: <input type="text" name="y"
value=" ">
Branch: <input type="text" name="branch" value=" ">
<input type="submit" name="button" value="SUBMIT">
</b></center></pre>
</body>
</html>

Registration.php

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Online_exam";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{
die("Connection failed: " . $conn->connect_error);
}
/*else
echo "Connection established";*/
$Name=$_POST['n'];
$RegNo=$_POST['reg'];
CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /
$CGPA=$_POST['cgpa'];
$Year=$_POST['y'];
$Branch=$_POST['branch'];
/*echo
$Name;
echo
$RegNo;
echo
$CGPA;
echo $Year;
echo
$Branch;*/
$sql = "CREATE TABLE regDetails(Name varchar(30) not null, RegNo int(15) not null,CGPA
floatnot null, Year varchar(5) not null, Branch varchar(5) not null)";

if ($conn->query($sql) === TRUE)


{
echo "Table regDetails created successfully";
}
else
{
echo "Error creating table: " . $conn->error;
}
$sql = "INSERT INTO regDetails (Name,RegNo,CGPA,Year,Branch)
VALUES
('$Name',$RegNo,$CGPA,'$Year','$Branch')";
if ($conn->query($sql) === TRUE)
{
echo "New record created successfully";
}
else
{
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


PERFORMANCE 25

VIVA 10
RECORD 15
TOTAL 50

RESULT:
Thus the real life database application for exam registration has been successfully executed.

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


EX.NO:13 CASE STUDY USING REAL LIFE DATABASE APPLICATIONS
DATE:
AIM:
To implement an online exam registration page with database connectivity using php
ALGORITHM:
STEP 1: Develop a webpage which includes all the fields for registering for an online exam
STEP 2: Develop a PHP page which receives the values that are given as an input in the registration page
STEP 3: Connect the registration page with the PHP page
STEP 4: Receive the values from registration page
STEP 5: Establish a connection with the database
STEP 6: Store the received values in the database
PROGRAM:
Registration.html
<html>
<body bgcolor="lightblue">
<p><center>REGISTRATION FORM</center></p>
<form action="Registration.php" method="post">
<center><pre><b> Student name: <input type="text" name="n" value=" ">
Register Number: <input type="text" name="reg" value=" ">
CGPA: <input type="text" name="cgpa" value=" ">
YEAR: <input type="text" name="y" value=" ">
Branch: <input type="text" name="branch" value=" ">
<input type="submit" name="button" value="SUBMIT">
</b></center></pre>
</body>
</html>
Registration.php
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Online_exam";
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error)
{

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /


die("Connection failed: " . $conn->connect_error);
}
/*else
echo "Connection established";*/
$Name=$_POST['n'];
$RegNo=$_POST['reg'];
$CGPA=$_POST['cgpa'];
$Year=$_POST['y'];
$Branch=$_POST['branch'];
/*echo $Name;
echo $RegNo;
echo $CGPA;
echo $Year;
echo $Branch;*/
$sql = "CREATE TABLE regDetails(Name varchar(30) not null, RegNo int(15) not null,CGPA float not
null, Year varchar(5) not null, Branch varchar(5) not null)";
if ($conn->query($sql) === TRUE)
{
echo "Table regDetails created successfully";
}
else
{
echo "Error creating table: " . $conn->error;
}
$sql = "INSERT INTO regDetails (Name,RegNo,CGPA,Year,Branch)
VALUES ('$Name',$RegNo,$CGPA,'$Year','$Branch')";
if ($conn->query($sql) === TRUE)
{
echo "New record created successfully";
}
else
{
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>

PERFORMANCE 25

VIVA 10
RECORD 15
TOTAL 50

Result:
Thus, the program was executed and output was verified successfully.

CS3481 DATABASE MANAGEMENT SYSTEMS LABORATORY/ II YEAR / IV SEM /

You might also like