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

student record

Uploaded by

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

student record

Uploaded by

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

EX.

NO: 1a DATABASE DEVELOPMENT LIFE CYCLE


DATE: Problem definition, Requirement analysis, Scope and Constraints

AIM

PROCEDURE
List of DDL commands:

• CREATE: This command is used to create the database or its objects (like table, index,
function, views, store procedure, and triggers).
• DROP: This command is used to delete objects from the database.
• ALTER: This is used to alter the structure of the database.
• TRUNCATE: This is used to remove all records from a table, including all spaces
• RENAME: This is used to rename an object existing in the database.
2. SQL CREATE command It is used to create a new table in the database.
Syntax:
CREATE TABLE TABLE_NAME (COLUMN_NAME DATATYPES[,. ..]);
Or
Create table "table_name" ("column1" "data type", "column2" "data type", "column3" "data type",..
"columnN" "data type");
Example creates a table called "Persons" that contains five columns: PersonID, LastName,
FirstName, Address, and City:
Example 1
CREATETABLE Persons ( PersonID int,
LastName varchar(255), FirstName varchar(255), Address varchar(255), City varchar(255)
)
a. SQL DROP Command:
• The DROP TABLE statement is used to drop an existing table in a database
• A SQL drop table is used to delete a table definition and all the data from a table.
• It is used to delete both the structure and record stored in the table.

Syntax: DROP TABLE table_name;


Example
DROP TABLE EMPLOYEE;
a. SQL ALTER Command: It is used to alter the structure of the database. This will modify the
characteristics of an existing attribute or to add a new attribute.
Syntax: To add a new column in the table
ALTER TABLE table_name ADD column_name COLUMN-definition;
To modify existing column in the table:
ALTER TABLE table_name MODIFY(column_definitions... );
b. SQL TRUNCATE:
The TRUNCATE TABLE statement is used to delete the data inside a table, but not the table itself. It
is used to delete all the rows from the table and free the space containing the table.
Syntax:
TRUNCATE TABLE table_name;
Example:
TRUNCATE TABLE EMPLOYEE;
c. SQL RENAME
Database user can easily change the name of the table by using the RENAME TABLE and ALTER
TABLE statement in SQL. This helps in changing the name of the table.
Syntax:
RENAME old_table _name To new_table_name ;

RESULT:
EX. NO: 2 DATABASE DESIGN USING CONCEPTUAL MODELING (ER-EER) –
TOP-DOWN APPROACH MAPPING CONCEPTUAL TO RELATIONAL
DATABASE AND VALIDATE USING NORMALIZATION
AIM:

DESCRIPTION:
ER model
 ER model stands for an Entity-Relationship model. It is a high-level data model. This
model is used to define the data elements and relationship for a specified system.
ER MODEL to RELATIONAL MAPPING

 The database can be represented using the notations, and these notations can be reduced to a
collection of tables.
 In the database, every entity set or relationship set can be represented in tabular form.

SAMPLE ENTITY-RELATIONSHIP DIAGRAM:


TABLE CREATION
CREATE TABLE SALESMAN (SALESMAN_ID NUMBER (4),
NAME VARCHAR2 (20),
CITY VARCHAR2 (20),
COMMISSION VARCHAR2 (20), PRIMARYKEY (SALESMAN_ID));
CREATE TABLE CUSTOMER1 (CUSTOMER_ID NUMBER (4),
CUST_NAME VARCHAR2 (20),
CITY VARCHAR2 (20),
GRADE NUMBER (3),
PRIMARY KEY (CUSTOMER_ID),
SALESMAN_ID REFERENCES SALESMAN (SALESMAN_ID) ON DELETE SET NULL);
CREATE TABLE ORDERS (ORD_NO NUMBER (5),
PURCHASE_AMT NUMBER (10, 2), ORD_DATE DATE,
PRIMARY KEY (ORD_NO),

CUSTOMER_ID REFERENCES CUSTOMER1 (CUSTOMER_ID) ON DELETE CASCADE,


SALESMAN_ID REFERENCES SALESMAN (SALESMAN_ID) ON DELETE CASCADE);

RESULT:
EX. NO: 3 IMPLEMENT DATABASE USING SQL DATA DEFINITION
DATE: WITH VIEWS
AIM:

VIEWS DESCRIPTION:
 A database view is a logical or virtual table based on a query. Views are queried just like tables.
 To create the view, we can select the fields from one or more tables present in database.
 A view can either have specific rows based on certain condition or all the rows of a table. A
DBA or view owner can drop a view with the DROP VIEW command.
TYPES OF VIEWS
• Updatable views – Allow data manipulation
• Read only views – Do not allow data manipulation
Sample table: Student_Detail

STU_ID NAME ADDRESS

1 Stephan Delhi
2 Kathrin Noida
3 David Ghaziabad
4 Alina Gurugram

Student_Marks

STU_I NAME MARKS AGE


D

1 Stephan 97 19
2 Kathrin 86 21
3 David 74 18
4 Alina 90 20

Creating view:
A view can be created using CREATE VIEW statement. Create a view from a single table or
multiple tables.
Syntax:
CREATE VIEW view_name AS SELECT column1, column2..... FROM table_name
WHERE condition;
1. Creating View from a single table
In this example, we create a View named DetailsView from the table Student_Detail.
Query:
CREATE VIEW DetailsView AS SELECT NAME, ADDRESS
FROM Student_Details WHERE STU_ID < 4;
Just like table query, we can query the view to view the data.
SELECT * FROM DetailsView;
2. Creating View from multiple tables
View from multiple tables can be created by including multiple tables in SELECT statement.
In this, view is created named MarksView from two tables Student_Detail and Student_Marks.
Query:
CREATE VIEW MarksView AS
SELECT Student_Detail.NAME, Student_Detail.ADDRESS, Student_Marks.MARKS FROM
Student_Detail, Student_Mark
WHERE Student_Detail.NAME = Student_Marks.NAME;
To display data of View MarksView:SELECT * FROM MarksView;
3. Deleting View - A view can be deleted using the Drop View statement.
Syntax: DROP VIEW view_name;
Example: If we want to delete the View MarksView, we can do this as:
DROP VIEW MarksView;
4. SQL Updating a View -
A view can be updated with the CREATE OR REPLACE VIEW statement.
SQL CREATE OR REPLACE VIEW Syntax
CREATE OR REPLACEVIEW view_name AS SELECTcolumn1, column2, ...
FROM table_name
WHERE condition;

RESULT:
EX. NO: 4 QUERY THE DATABASE USING SQL MANIPULATION
DATE:
AIM:

DESCRIPTION:
SQL DATA MANIPULATION LANGUAGE (DML)
 DML commands are SQL commands, used to manipulation of data i.e., modify the data
present in the database
 It is responsible for all form of changes in the database.
List of DML commands:
 INSERT : It is used to insert data into a table.
 UPDATE: It is used to update existing data within a table.
 DELETE : It is used to delete records from a database table.
 SELECT: It is used to query or retrieve data from a table in the database
a. SQL INSERT: SQL INSERT statement is used to insert a single or multiple data into row
of a table.
Syntax:
INSERT INTO TABLE_NAME
(col1, col2, col3,. ..................... col N)
VALUES (value1, value2, value3, ....................... valueN);
Or INSERT INTO TABLE_NAME
VALUES (value1, value2, value3, ....................... valueN);
For example:
In SQL, You can insert the data in two ways:
 Without specifying column name
 By specifying column name
Sample Table - EMPLOYEE

EMP_ID EMP_NAME CITY SALARY AGE

1 Angelina Chicago 200000 30

2 Robert Austin 300000 26


3 Christian Denver 100000 42

4 Kristen Washington 500000 29

5 Russell Los angels 200000 36

1. Without specifying column name Syntax: INSERT INTO TABLE_NAME


VALUES (value1, value2, value 3, ............................. Value N);
Query: INSERT INTO EMPLOYEE VALUES (6, 'Marry', 'Canada', 600000, 48);
2. By specifying column name
To insert partial column values, you must have to specify the column names.
Syntax
INSERT INTO TABLE_NAME
[(col1, col2, col3,. ................ col N)]
VALUES (value1, value2, value 3, ................. Value N);
Query:INSERT INTO EMPLOYEE (EMP_ID, EMP_NAME, AGE) VALUES (7, 'Jack', 40);
b. SQL UPDATE:
 This command is used to update or modify the value of a column in the table.
 SQL UPDATE statement is used to modify the data that is already in the database.
 The condition in the WHERE clause decides that which row is to be updated.
Syntax:
UPDATE table_name
SET column1 = value1, column2 = value2, ... [WHERE CONDITION]
Sample Table: EMPLOYEE

EMP_ID EMP_NAME CITY SALARY AGE

1 Angelina Chicago 200000 30

2 Robert Austin 300000 26

3 Christian Denver 100000 42

4 Kristen Washington 500000 29

5 Russell Los angels 200000 36

6 Marry Canada 600000 48


Updating single record
Update column EMP_NAME and set the value to 'Emma' in the row where SALARY is 500000.
Syntax: UPDATE table_name
SET column_name = value WHERE condition;
Query
UPDATE EMPLOYEE SET EMP_NAME = 'Emma'
WHERE SALARY = 500000;
Updating multiple records
If you want to update multiple columns, you should separate each field assigned with a
comma.Syntax UPDATE table_name
SET column_name = value1, column_name2 = value2 WHERE condition;
Query
UPDATE EMPLOYEE
SET EMP_NAME = 'Kevin', City = 'Boston' WHERE EMP_ID = 5;
Without use of WHERE clause Syntax: UPDATE table_name
SET column_name = value1;
Query: UPDATE EMPLOYEE SET EMP_NAME = 'Harry';
c. SQL DELETE: It is used to remove one or more row from a table.
Syntax:
DELETE FROM table_name [WHERE condition];
Example :
Suppose, the EMPLOYEE table having the following records:

EMP_ID EMP_NAME CITY PHONE_NO SALARY

1 Kristen Chicago 9737287378 150000

2 Russell Austin 9262738271 200000

3 Denzel Boston 7353662627 100000

4 Angelina Denver 9232673822 600000

5 Robert Washington 9367238263 350000

6 Christian Los angels 7253847382 260000

The following query will DELETE an employee whose ID is 3.


SQL> DELETE FROM EMPLOYEE WHERE EMP_ID = 3;
Deleting Single Record
Delete the row from the table EMPLOYEE where EMP_NAME = 'Kristen'. This will delete only the
fourth row.
Query
DELETE FROM EMPLOYEE WHERE EMP_NAME = 'Kristen';
Deleting Multiple Record
Delete the row from the EMPLOYEE table where AGE is 30.
Query
DELETE FROM EMPLOYEE WHERE AGE= 30;
Delete all of the records
Delete all the row from the EMPLOYEE table. After this, no records left to display. The EMPLOYEE
table will become empty.
Syntax
DELETE * FROM table_name;
or
DELETE FROM table_name;
Query
DELETE FROM EMPLOYEE;
DATA QUERY LANGUAGE - DQL is used to fetch data from database. It uses only one command
- SELECT
SELECT:
SELECT statement is used to query or retrieve data from a table in the database. The returns data is
stored in a table, and the result table is known as result-set.
Syntax:
SELECT expressions FROM TABLES
WHERE conditions;
Or
SELECT column1, column2, ... FROM table_name;
For example:
Use the following syntax to select all the fields available in the table: SELECT * FROM table_name;
Example: EMPLOYEE

EMP_ID EMP_NAME CITY PHONE_NO SALARY

1 Kristen Chicago 9737287378 150000

2 Russell Austin 9262738271 200000

3 Angelina Denver 9232673822 600000

4 Robert Washingto 9367238263 350000


n

5 Christian Los angels 7253847382 260000

To fetch the EMP_ID of all the employees, use the following query: SELECT EMP_ID FROM
EMPLOYEE;
To fetch the EMP_NAME and SALARY, use the following query: SELECT EMP_NAME, SALARY
FROM EMPLOYEE;
To fetch all the fields from the EMPLOYEE table, use the following query: SELECT * FROM
EMPLOYEE

RESULT:
EX. NO: 5a QUERYING/MANAGING THE DATABASE USING SQL
DATE: PROGRAMMING PROCEDURES
AIM:

Table Creation:
create table bank(acc_no number, name varchar2(10), bal number);
Table created.

Inserting Values in table:


insert into bank values (100,‘Anil‘,50000)
1 row created.
insert into bank values (101,‘Abi‘,10000)
1 row created.
insert into bank values (102,‘Bavi‘,2500)
1 row created.
insert into bank values (103,‘Chandru‘,1000)
1 row created.
insert into bank values (104,‘Divakar‘,20000)
1 row created.
select * from bank;
CREATING A PROCEDURE
Create a procedure for deposit & withdrawal of money in account in a Bank table.
create or replace procedure bank_pro(opt number, amount number, n number) as balance number;
begin
select bal into balance from bank where acc_no=n; if opt=1 then
balance:= balance+amount;
update bank set bal=balance where acc_no=n;
commit;
dbms_output.put_line('Balance after deposition is '||balance); elsif opt=2 then
balance:=balance-amount;
if balance<1000 then
dbms_output.put_line('Cannot withdraw… Balance lower than'||balance);
else
update bank set bal=balance where acc_no=n;
commit;
dbms_output.put_line('Balance after withdrawal is'||balance);
end if;
end if;
end ;
/
Procedure created.
PROCEDURE CALL - DEPOSIT
begin bank_pro(1,40000,100); end;
/
Balance after deposition is 90000 Statement processed.
select * from bank;
PROCEDURE CALL - WITHDRAW
begin bank_pro(2,1500,102); end;
/
PROCEDURE CALL - WITHDRAW
begin bank_pro(2,1500,103); end;
/

RESULT:
EX. NO: 5b QUERYING/MANAGING THE DATABASE USING SQL
DATE: PROGRAMMING FUNCTIONS
AIM:

TABE CREATION:
create table bank_acc(acc_no number, b_name varchar2(10), balance number);
Table created.
insert into bank_acc values (100,‘SBI‘, 25000)
1 row created.
insert into bank_acc values (101,‘SBT‘, 5000)
1 row created.
insert into bank_acc values (102,‘FEDERAL‘, 10000)
1 row created.
insert into bank_acc values (103,‘AXIS‘,15000)
1 row created.
insert into bank_acc values (104,‘CANARA‘, 50000)
1 row created
select * from bank_acc;
WITHDRAW FUNCTION:
Create a function for withdrawing money from an account in bank
PROGRAM:
create or replace function withdraw (n in number, amt in number) return number is b number;
begin
select balance into b from bank_acc where acc_no=n;
if b-500>amt then
b:=b-amt;
update bank_acc set balance=b where acc_no=n;
else
dbms_output.put_line('can not withdraw');
end if;
return b;
end;
/ Function created
WITHDRAW FUNCTION CALL:
Calling function from a PL\SQL block:
Declare n number; begin
n:=withdraw(100,20000); end/
Statement processed.
select * from bank_acc;
Calling function from a PL\SQL block: declare
n number;
begin n:=withdraw(101,20000);
end/
can not withdraw Statement processed. select * from bank_acc;
DEPOSIT FUNCTION:
Create a function for depositing money to an account in a bank
create or replace function deposit(n in number, amt in number) return number is b number;
begin
select balance into b from bank_acc where acc_no=n;
b:=b+amt;
update bank_acc set balance=b where acc_no=n;
return b;
end
/ Function created
DEPOSIT FUNCTION CALL
Calling function from a PL/SQL block
declare
n number; begin
n:=deposit(104,5000); end/
Statement processed.
select * from bank_acc;

RESULT:
EX. NO: 5c QUERYING/MANAGING THE DATABASE USING SQL
DATE: PROGRAMMING TRIGGERS
AIM:

SYNTAX:
Create trigger trigger name BEFORE | AFTER
DELETE, INSERT, UPDATE
ON table name FOR EACH ROW BEGIN
Executable-statements END;
Database creation:
create table student(sid number(4), name varchar(30), sub1 number(2), sub2 number(2), sub3
number(2), total number(3), per number(3));
Table Description: Desc student;

Before Trigger Execution: Inserting Values in table:


insert into student values(1, 'Nivetha', 50, 60, 70, 0, 0);
1 row(s) inserted.
select * from student;
CREATING TRIGGER
create trigger strigger before insert on Student for each row Begin
update student set Student.total = Student.sub1 + Student.sub2 + Student.sub3, Student.per =
Student.total/3;
end;
/
After Trigger Execution Inserting Values in table:
Insert into student values(2, 'Rithani', 90, 80, 90, 0, 0);
1 row(s) inserted.
select * from student
insert into student values(3, 'Sankar', 90, 90, 90, 0, 0);
1 row(s) inserted.
select * from student;
insert into student values(4, 'Vijay', 95, 95, 95, 0, 0);
1 row(s) inserted.
select * from student;

RESULT:
EX. NO: 5d CREATION OF A DATABASE USING SQL QUERIES DDL, DML
DATE:

AIM

DDL COMMANDS DESCRIPTION CREATE

SQL> create table student(sno number(3),name varchar(20),marks number(3),dep varchar(2),age


number(2));
Table created Sql> desc student;
ALTER
SQL> alter table student add(ph_no number(10)); Table altered
Sql> desc student;
MODIFY
SQL> alter tables student modify(dep varchar(5)); Table altered
Sql> desc student;
TRUNCATE
SQL> truncate table student; Table truncated
SQL> select * from student; No rows selected
DROP
SQL> alter table student drop column ph_no ; Table altered
SQL> desc student ;
DML COMMANDS
INSERT
SQL> insert into student values(01,‘Manoj‘,99,‘IT‘,18) ; 1 row created
SQL>insert into student values(02,‘Ramana‘,98,‘IT‘,19); 1 row created
SQL>insert into student values(03,‘Samy‘,90,‘CSE‘,17); 1 row created
SQL>insert into student values(04,‘Prabha‘,99, ‘CSE‘,16); 1 row created
SELECT SQL> select * from student;
UPDATE
SQL>update student set age=18 where sno=‘04‘; 1 row updated
SQL>select * from student;

DELETE
SQL> delete from student where sno=‘03‘; 1 rows deleted
SQL>select * from student;

RESULT:
EX. NO: 6 DATABASE DESIGN USING NORMALIZATION
DATE:
AIM:

DESCRIPTION:
NORAMALIZATION OF TABLE
 Database normalization is the process of removing redundant data from tables in order to
improve storage efficiency, data integrity, and scalability
 Normalization is process of minimizing redundancy from a relation. Redundancy in relation
may cause insertion, deletion, and update anomalies. So, it helps to minimize redundancy in relations.
 Normal forms are used to eliminate or reduce redundancy in database tables
FIRST NORMAL FORM
EMPLOYEE table:

EMP_ID EMP_NAME EMP_PHONE EMP_STATE

14 John 7272826385, UP
9064738238

20 Harry 8574783832 Bihar

12 Sam 7390372389, Punjab


8589830302

The decomposition of the EMPLOYEE table into 1NF has been shown below:
2. SECOND NORMAL FORM:
TEACHER table

TEACHER_ID SUBJECT TEACHER_AGE

25 Chemistry 30

25 Biology 30

47 English 35

83 Math 38

83 Computer 38
THIRD NORMAL FORM (3NF)
EMPLOYEE_DETAIL table:

EMP_ID EMP_NAME EMP_ZIP EMP_STATE EMP_CITY

222 Harry 201010 UP Noida

333 Stephan 02228 US Boston

444 Lan 60007 US Chicago

555 Katharine 06389 UK Norwich

666 John 462007 MP Bhopal

4.BOYCE CODD NORMAL FORM (BCNF)


Boyce-Codd Normal Form (BCNF) is an extension of Third Normal Form.
BCNF states that For any non-trivial functional dependency, X → A, X must be a super-key.
In the above Example, Stu_ID is the super-key in the relation Student_Detail and Zip is the super-key
in the relation ZipCodes.
Stu_ID → Stu_Name, Zip Zip → City

RESULT:
EX. NO : 6a SQL PROGRAMMING USING FUNCTIONS
DATE:

AIM:

TABLE CREATION: user1 table


Create table user1(id number(10) primary key, name varchar2(100));
Inserting Values in user1 Table:
After inserting 5 rows, Final table will be:
Insert into user1 values(101,’Rahul’);
Insert into user1 values(102,’Risha’);
Insert into user1 values(103,’Rithu’);
Insert into user1 values(104,’Roja’);
Insert into user1 values(105,’Rubika’);
Select * from user1
CREATE FUNCTION:
CREATE OR REPLACE FUNCTION total Customers RETURN number IS
total number(2) := 0; BEGIN
SELECT count(*) into total FROM user1;
RETURN total; END;
/
FUNCTION CALL:
DECLARE
c number(2); BEGIN
c := totalCustomers();
dbms_output.put_line('Total no. of Customers: ' || c); END;
/

RESULT:
EX. NO: 6b FUNCTIONS IN SQL PROGRAMMING
DATE:

AIM:

FUNCTION CREATION
create or replace function add(n1 in number, n2 in number) return number is
n3 number(8);
begin
n3 :=n1+n2;
return n3;
end;
/
FUNCTION CALL: Program to call the function add()
DECLARE
n3 number(2); BEGIN
n3 := add(11,22);
dbms_output.put_line('Addition is: ' || n3); END;
/

RESULT:
EX. NO: 7 DEVELOP DATABASE APPLICATIONS USING IDE (NETBEANS)
DATE:

AIM:

JDBC DESCRIPTION
Java has defined its own API (JDBC API) that uses JDBC drivers (written in Java language). JDBC
API is used to handle database using Java program and can perform the following activities:
1. Connect to the database
2. Execute queries and update statements to the database
3. Retrieve the result received from the database.
Java Database Connectivity with 5 Steps
There are 5 steps to connect any java application with the database using JDBC.
These steps are as follows:
1) Register the driver class
2) Create the connection object
3) Create the Statement object
4) Execute the query
5) Close the connection object
Java program code Test.java
import java.sql.*; class TestDB
{
public static void main(String ar[])
{
Try
{
String url="jdbc:odbc:mydsn";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection c=DriverManager.getConnection(url);
Statement st=c.createStatement();
ResultSet rs=st.executeQuery("select * from login");
while(rs.next())
{
System.out.println(rs.getString(1) + "" + rs.getString(2)+ "" rs.getString(2));
}
}
catch(Exception ee)
{
System.out.println(ee);
} } }

RESULT:
EX. NO: 8 DATABASE DESIGN USING EER-to-ODB MAPPING/ UML CLASS
DATE: DIAGRAM

AIM:

PROGRAM:

Creating Author table


CREATE TABLE Author (
AuthorID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
BirthDate DATE
);
Creating Book table
CREATE TABLE Book (
ISBN VARCHAR(13) PRIMARY KEY,
Title VARCHAR(255),
PublicationYear INT,
AuthorID INT,
FOREIGN KEY (AuthorID) REFERENCES Author(AuthorID)
);
In this example:
- The `Author` table has columns for `AuthorID`, `FirstName`, `LastName`, and `BirthDate`.
- The `Book` table has columns for `ISBN`, `Title`, `PublicationYear`, and `AuthorID`. The
`AuthorID` column in the `Book` table is a foreign key referencing the `Author` table.
Output:

+-------------------+ +------------------+
| Author | | Book |
+-------------------+ +------------------+
| AuthorID | | ISBN |
| FirstName | | Title |
| LastName | | PublicationYear |
| BirthDate | | AuthorID (FK) |
+-------------------+ +------------------+

RESULT:
EX. NO: 9 OBJECT FEATURES OF SQL-UDTS AND SUB-TYPES, TABLES USING
DATE: UDTS, INHERITANCE, METHOD DEFINITION

AIM:

USER DEFINED TYPE (UDT)


 Most important object-oriented feature added to SQL is a user defined type (UDT). The definition
of a UDT is similar to the definition of a class.
 It can include attributes and methods and supports inheritance. The following expression defines a
new UDT called Person.
create type Person as (pid varchar(10), pname varchar(20)) not final
create type Address as Object (street varchar(30), city varchar(30), state char(2), zip char(10)) not
final
create type Person as Object ( pid varchar(10), pname varchar(30), pAddr Address) not final
create table Agents of Agent (pid primary key)
insert into Agents values ('001', 'John Smith', Address('123 Main', 'Lal street)
OBJECT FEATURES OF SQL
(b) Using UDTs as types for attributes such as Address and Phone
CREATE TYPE STREET_ADDR_TYPE AS ( NUMBER VARCHAR(5), STREET_NAME
VARCHAR(25), APT_NO VARCHAR(5),SUITE_NO VARCHAR(5));
CREATE TYPE USA_ADDR_TYPE AS ( STREET_ADDR STREET_ADDR_TYPE, CITY
VARCHAR(25),ZIP VARCHAR(10));
CREATE TYPE USA_PHONE_TYPE AS ( PHONE_TYPE VARCHAR(5),AREA_CODE
CHAR(3),PHONE_NUM CHAR(7));
(c) Specifying UDT for PERSON_TYPE
CREATE TYPE PERSON_TYPE AS (NAME VARCHAR(35),SEX CHAR,BIRTH_DATE
DATE, PHONES USA_PHONE_TYPE ARRAY[4],ADDR USA_ADDR_TYPE
INSTANTIABLE
NOT FINAL
INSTANCE METHOD AGE() RETURNS INTEGER; CREATE INSTANCE METHOD AGE()
RETURNS INTEGER
FOR PERSON_TYPE BEGIN
RETURN /* CODE TO CALCULATE A PERSON’S AGE FROM TODAY’S DATE AND
BIRTH_DATE */
END;
);
(d) Specifying UDTs for STUDENT_TYPE and EMPLOYEE_TYPE as two subtypes of
PERSON_TYPE.
CREATE TYPE GRADE_TYPE AS ( COURSENO CHAR(8),SEMESTER VARCHAR(8),YEAR
CHAR(4),GRADE CHAR);
CREATE TYPE STUDENT_TYPE UNDER PERSON_TYPE AS ( MAJOR CODE CHAR (4),
STUDENT_ID CHAR (12),DEGREE VARCHAR (5), TRANSCRIPT GRADE_TYPE ARRAY
[100]
INSTANTIABLE
NOT FINAL
INSTANCE METHOD GPA() RETURNS FLOAT; CREATE INSTANCE METHOD GPA()
RETURNS FLOAT
FOR STUDENT_TYPE BEGIN
RETURN /* CODE TO CALCULATE A STUDENT’S GPA */
END;
);
CREATE TYPE EMPLOYEE_TYPE UNDER PERSON_TYPE AS ( JOB_CODE CHAR(4),
SALARY FLOAT,SSN CHAR(11) INSTANTIABLE NOT FINAL );
CREATE TYPE MANAGER_TYPE UNDER EMPLOYEE_TYPE AS ( DEPT_MANAGED CHAR
(20)
INSTANTIABLE
);
(e) Creating tables based on some of the UDTs, and illustrating table inheritance,

CREATE TABLE PERSON OF PERSON_TYPE CREATE TABLE EMPLOYEE OF


EMPLOYEE_TYPE
UNDER PERSON;
CREATE TABLE MANAGER OF MANAGER_TYPE UNDER EMPLOYEE;
CREATE TABLE STUDENT OF STUDENT_TYPE UNDER PERSON;

RESULT:
EX. NO: 10 QUERYING THE OBJECT-RELATIONAL DATABASE
DATE: USING OBJET QUERY LANGUAGE

AIM:

CREATING DATABASE AND TABLE


Create databases and tables with the create command
Create command to create a database create database database_name ;
Create command to create a table
create table database_name.table_name (
column_name [constraints ] [default ] ,
[ column_name [ constraints ] [default ] , ] [ additional_columns ]
[ unique ( column_name ) , ] [ counter ( column_name ) , ]
[ timestamp ( column_name ) ]
);
INSERTING DATA INTO A TABLE
Use the insert keyword to insert data into a table.
Syntax: insert into database_name.table_name
(
Column [ , column ] [ , column ] [ ... ]
)
values (
Data [ , data ] [ , data ]
[ ... ]
);
SELECTING DATA FROM A TABLE
 Select keyword is used to Query or retrieve the data in a table Syntax:
select comma_separated_column_list
from database_name.table_name
[ where conditional_test ]
[ order by field_name [asc|desc] ];
The * symbol can be used in a select statement to return all the columns of the table.
UPDATE RECORDS IN TABLE
 Use the update keyword to update an existing record in a table.
Syntax
The following syntax shows how to use the update keyword. Update database_name.table_name
set column = value [ , column = value ... ] [ where conditional_test ] ;
If the update statement is used without a where condition, all records are updated.
DATABASE AND TABLE LISTINGS
 Use the show keyword to list the databases, columns, or tables or the current service.
Syntax
show databases ;
show tables from database_name ; show table database_name.table_name ;
DELETION OF A RECORD FROM A DATABASE TABLE
 Delete a record from a table using the delete command.
Syntax: how to use the delete command.
Delete from database_name.table_name [ where conditional_test ] ;

RESULT:

You might also like