0% found this document useful (0 votes)
56 views5 pages

Ex No:1 Table Creation: Field Name Constraint Type Size

The document describes creating tables and inserting, updating, and querying data in Oracle SQL. It includes creating tables with various fields and constraints, inserting sample data, performing selects with filters, updating records, and joining tables in queries. Examples include creating employee, student, and staff tables, inserting records, selecting records that match criteria like names starting with "S", updating a record, and performing aggregates and joins in queries.

Uploaded by

Arumugam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views5 pages

Ex No:1 Table Creation: Field Name Constraint Type Size

The document describes creating tables and inserting, updating, and querying data in Oracle SQL. It includes creating tables with various fields and constraints, inserting sample data, performing selects with filters, updating records, and joining tables in queries. Examples include creating employee, student, and staff tables, inserting records, selecting records that match criteria like names starting with "S", updating a record, and performing aggregates and joins in queries.

Uploaded by

Arumugam
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

EX NO:1

TABLE CREATION

Create a table with following fields:

Employee table:
Field name Constraint Type Size
Employee_no Primary key Character 6
Employee_name Character 30
Dob Date
Doj Date

QUERIES:
Create table employees(employee_no varchar(6)not null,emp_name varchar(30),dob date,doj
date,primary key(employee_no));

Table created.

SQL> select * from employees;

EMPLOY EMP_NAME DOB DOJ


------ ------------------------------ --------- ---------
1 mounika 25-JUL-97 07-JUN-15
2 pavithra 21-SEP-97 03-MAY-00
3 siva 27-FEB-78 12-APR-12
4 ram 09-AUG-95 22-NOV-11
6 prabha 12-JUL-95 30-DEC-87

EX NO:2
INSERT AND UPDATE

Student table:

Field name Constraint Type Size


Roll_no Primary key Character 6
Student_name Character 30
Dob Date
External Check Number 2
Internal Check Number 3

Execute the ollowing queries:


1. Insert records for all the students.
2. Select the records for students.

1
3. Select the students whose name start with S.
4. Update the records.

QUERIES:

SQL> create table classmarks(roll_no character(6),student_name character(30),dob date,external


varchar(2) check(external<=60),internal varchar(3) check(internal<=40),primary key(roll_no));

Table created.

Insert into classmarks values


('&roll_no','&student_name','&dob','&external','&inter');

Enter value for roll_no: 12


Enter value for student_name: siva
Enter value for dob: 26 mar 1997
Enter value for external: 45
Enter value for internal: 34
old 1: insert into classmarks values('&roll_no','&student_name','&dob','&external','&internal')
new 1: insert into classmarks values('12','siva','26 mar 1997','45','34')

1 row created.

SQL> select * from classmarks;

ROLL_N STUDENT_NAME DOB EX INT


------ ------------------------------ --------- -- ---
12 siva 26-MAR-97 45 34
13 mouni 25-JUL-96 57 36
14 malini 30-MAY-54 56 38
15 sanjay 15-APR-00 58 36
16 sambath 22-JUN-65 49 33
17 salu 28-NOV-76 34 22
6 rows selected.

SQL> select * from classmarks where student_name like's%';


\
ROLL_N STUDENT_NAME DOB EX INT
------ ------------------------------ --------- -- ---
12 siva 26-MAR-97 45 34
15 sanjay 15-APR-00 58 36
16 sambath 22-JUN-65 49 33
17 salu 28-NOV-76 34 22
SQL> update classmarks set student_name='akil' where student_name='malini';

1 row updated.

2
SQL> select * from classmarks;
ROLL_N STUDENT_NAME DOB EX INT
------ ------------------------------ --------- -- ---
12 siva 26-MAR-97 45 34
13 mouni 25-JUL-96 57 36
14 akil 30-MAY-54 56 38
15 sanjay 15-APR-00 58 36
16 sambath 22-JUN-65 49 33
17 salu 28-NOV-76 34 22

6 rows selected.

SQL> commit;

Commit complete.

SQL> select * from classmarks where student_name like'mouni%';

ROLL_N STUDENT_NAME DOB EX INT


------ ------------------------------ --------- -- ---
13 mouni 25-JUL-96 57 36

EX NO: 3
REFERENCE KEY

Create a table with following fields:

Staff table:
Field name Constraint Type Size
Staff_no Primary key Character 6
Staff_name Character 30
Dob Date
Dept_code Foreign key Character 4
Designation Character 15
Basic Number 7,2

Department table:
Field name constraint Type Size
Dept_code Primary key Character 4
Dept_name Character 30

Execute the following queries:


1. To list the staff who joined 2 years back.
2. To list the staff in computer science dept.
3. To list the staff_name and the dept_name in which he/she works.

3
4. To list the maximum and minimum salary in each dept.
5. To list the dept along with the total amount spent on salary
6. To list the name of the employees who draw the salary more than the average salary.

QUERIES:

create table dpmt(dpmt_code character(4),dpmt_name character(30),primary key(dpmt_code));

Table created

insert into dpmt values('&dpmt_code','&dpmt_name');

SQL> insert into dpmt values('&dpmt_code','&dpmt_name');

Enter value for dpmt_code: 555


Enter value for dpmt_name: bcom
old 1: insert into dpmt values('&dpmt_code','&dpmt_name')
new 1: insert into dpmt values('555','bcom')

1 row created.

SQL> select * from dpmt;

DPMT DPMT_NAME
---- ---------------------------
555 bcom
111 bca
222 com sci
333 inftec
444 biotec

create table stf(staff_no character(6),staff_name character(30),doj date,dpmt_code


character(4),designation character(15),basic number(7,2),primary key(staff_no),foreign
key(dpmt_code) references dpmt(dpmt_code));

table created
SQL> insert into stf
values('&staff_no','&staff_name','&dob','&dpmt_code','&designation','&basic');

Enter value for staff_no: 11


Enter value for staff_name: meena
Enter value for dob: 17-JUL-97
Enter value for dpmt_code: 111
Enter value for designation: tutor
Enter value for basic: 40000
1 row created.

4
SQL> select staff_name from stf where doj<sysdate-730;

STAFF_NAME
------------
meena
lakshmi
siva
SQL>select staff_name,dept_name from stf where dpmt_name=comsci;

STAFF_NAME DEPT_NAME
------------- -----------------
Mounika comsci
Siva comsci

SQL> select staff_name,dpmt_name from stf where depmt_name=infotec;

STAFF_NAME DPMT_NAME
------------------------------ ----
meena infotec

SQL> select min(basic),max(basic),dpmt_code from stf group by dpmt_code;

MIN(BASIC) MAX(BASIC) DPMT


---------- ---------- ----
10000 40000 111
20000 20000 222

SQL> select sum(basic),dpmt_code from stf group by dpmt_code;

SUM(BASIC) DPMT_CODE
---------- ----
50000 111
40000 222
SQL> select staff_name from stf where basic>=(select avg(basic)from stf);
STAFF_ STAFF_NAME DPMT BASIC
------ ----------- ------------- -------

12 lakshmi bca 40000

You might also like