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

Assi1 5

This document provides instructions and assignments for students to practice SQL statements like CREATE TABLE, DROP TABLE, ALTER TABLE, INSERT INTO, and SELECT in Oracle. It includes 4 assignments to create and populate tables to practice different SQL statements and concepts like constraints, data types, joins etc. It also provides examples of basic and advanced SELECT queries using operators like IN, BETWEEN, LIKE and logical operators.

Uploaded by

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

Assi1 5

This document provides instructions and assignments for students to practice SQL statements like CREATE TABLE, DROP TABLE, ALTER TABLE, INSERT INTO, and SELECT in Oracle. It includes 4 assignments to create and populate tables to practice different SQL statements and concepts like constraints, data types, joins etc. It also provides examples of basic and advanced SELECT queries using operators like IN, BETWEEN, LIKE and logical operators.

Uploaded by

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

FY IT & CS Semester-1

Practical Assignment of DBMS


No Practical List
1 Introduction of SQL DDL statement: CREATE TABLE and DATA TYPE
notes Practice
2 Introduction of SQL DDL statement: CREATE TABLE examples
3 Introduction of DROP TABLE and SELECT Statement Notes
4 CREATE TABLE with Constraints: Primary Key, NOT NULL

NOTE: Practice assignment after notes

Write about CREATE TABLE statement in your notebook.

Answer:

Purpose: To create the table according to definition.

Syntax:

CREATE [OR REPLACE] TABLE table-name

Column-name1 datatype(size) [Constraints],

Column-name1 datatype(size) [Constraints],

Column-name1 datatype(size) [Constraints],

[Constraints]

);

NOTE: Always [ ] indicates optional for any statement.


Example: To create a table for book details.

Let’s understand the concept of how to create table of book


information.

Step-1: Decide the proper table-name according to given information.

Here in this example, it says about book details. So, let’s take
name of table as tbl_book or book_tbl, or book_details or
book_master.

Step-2: Decide the proper name of field-names for table-name.

Here is in this example, ISBN number of Book, Title of Book,


Price of Book, Publisher of book, Edition of book, Authors of book, etc..

So, as you see above details are there according to above discussion:

Description Field-name
ISBN number of Book B_ISBN
Title of Book B_title
Price of Book B_price
Publisher of book B_publisher
Edition of book B_edition
Author’s name of book B_author

Step-3: Decide the proper datatype of field-names for table-name.

No. Field-name Data type Size


1 B_ISBN Number 10
2 B_title Varchar 20
3 B_price Number 10,2
4 B_publisher Varchar 10
5 B_edition Varchar 10
6 B_author Varchar 10
Step-4: Use CREATE TABLE statement.

CREATE OR REPLACE TABLE book_details

B_ISBN number(10),

B_title varchar(20),

B_price number(10,2),

B_publisher varchar(10),

B_edition varchar(10),

B_author varchar(10)

);

Step-5: Select the whole statement and click on “RUN” button.

Step-6: Message is display “Table Created.” Otherwise you get error


message.

Read error, and do changes according in statement. Again select and


run the statement until get message as above mention.
Optional: Read or notedown below (if you want)
Write Oracle data types.
********

For more help Link: https://www.databasestar.com/oracle-data-types/

Practice Assignment-1
Aim: SQL DDL statements: CREATE TABLE

NOTE: URL = 127.0.0.1:8081/apex

User name: system

Password: admin123

1. Create table the details of bank’s customer with proper field


names, data type and size.
2. Crete table of customer information with proper field names, data
type and size.
3. Create table of student with proper field names , data type and
size.
4. Create table of employee with proper field names , data type and
size.
5. Create table of product with proper field names , data type and
size.

NOTE: Make .docx file , copy and paste assignment work

Practice Assignment-2
Aim: SQL DDL statements: CREATE TABLE, DROP TABLE and ALTER
TABLE with ADD option

1. Drop the table of bank’s customer.


2. Delete the table of customer.
3. Add the field of enrollment number(ENO datatype is varchar2 and
size is 8) with student with proper field names , data type and
size.
4. Add the field DA, HRA and Gross Salary with datatype Number
and size is 10,2.
5. Create table of order details with following format.

Field Name Data type Size


Order_id Number 3
Order_date Date
Prod_id Varchar2 4
Prod_name Varchar2 10
Price Number 10,2

6. Create table of passport details with following format.

Field Name Data type Size


Passport_ID Varchar2 10
Name_cust Varchar2 20
Gender Varchar2 10
Address Varchar2 20
City Varcahr2 10
Pincode Number 6

*******

Practice Assignment-3
Aim: More practice on create tables and INSERT INTO statement

Q-1: Decide table name as per following fields. And create the table.

Q-2: Decide table name as per following fields. And create the table.
Q-3: Decide table name and datatype as per following records. And
create the table.

Q-4: Decide table name and datatype as per following records. And
create the table.

******

NOTE:
Help for INSERT INTO Statement:
Syntax:

INSERT INTO table-name(Column-name1,col-nam2,….)

Values(value-1,valu-2,…..);

Example:

INSERT INTO STUDENT(RNO,NAME,GENDER,MARKS,BIRTH_DATE)

VALUES(11,’RAM’,MALE’,456,’25-JAN-2002’);
Display all the records using following statement:

SELECT *

FROM student;

Get format of date using following statement:

SELECT SYSDATE

FROM DUAL;

****

Extra Practice Assignment-3-A


1. Create the following tables using following
format:
Table name : Order_details
No. Field-name Data size constraints
type
1 Order_no Number 3 NOT NULL
2 Order_date Date
3 Item_code Number 3
4 Item_desp Varchar2 20
5 Qty Number 10,2 Not null
6 Item_rate Number 10,2 Not null
7 Total_amt Number 10,2 Default
100.00

Q-2. Add the field “email” varchar2 data type ,size


is 20.
Q-3. Insert at least 5 records in each table.
Q-4 Insert at least 5 records in each table of Practice
assignment -1 and assignment-2.
**********
NOTE: You have to create all tables with constraints and insert all the
records as per given below format.

Practical Assignment-1
Aim: CREATE TABLE with constraints AND INSERT INTO STATEMENT
CREATE FOLLOWING TABLES: STUDENT ENROLLMENT SYSTEM
NOTE: YOU CAN USE PRACTICAL ASSIGNMENT -1 TABLES FOR
ALL PRACTICAL WORK.

Practical Assignment-2
Aim:ALTER TABLE AND DROP TABLE STATEMENT.

1. ADD constraints NOT NULL in credits field of course.


2. Add a new field as “Fees” in course table with number data type and
size is 10,2
3. Modify the field size Major in student table take as varchar and size
is 20.
4. Add a new field name as “contact number” in student table with
proper data type and size.
5. Modify the data type of gender as varchar of student table.
6. ADD primary key constraints in course number in course table and
student_ID in student table and student_ID in student table
7. Add foreign key constraint in enrollment table as course number in
course table
[Kindly save your all queries of create and Insert into queries in word
file before perform following queries]
8. Delete the column of fees of course table.
9. Drop the table of course.
10. Delete the major and contact number field of student able
11. Add the new field in enrollment table as “enroll-date” with proper
data type and size.
***************
NOTE: YOU CAN USE PRACTICAL ASSIGNMENT -1 & 2 TABLES
FOR ALL PRACTICAL WORK.

Practical Assignment-3
Aim: SELECT statement with IN,BETWEEN, LIKE and
Logical operators

Simple SELECT Query

1. Display all records from course table.

2. Display all records from Enrollment table.

3. Display all records from student table.

4. Retrieve course number of course from Course table.

5. Retrieve student id of student from student table.

6. Retrieve course number and Title from Course table.

7. Display First Name , status and grade from student table.

Simple SELECT Query with Where clause

8. Display all those records course Title is ‘Basic English’ from course table.

9. Display all those records of students whose student id is ‘777349993’ from student
table.

10. Display all those records of students whose course number is ‘CIS326’ from
Enrollment table.

11. Display all those records of students whose grade is ’2’ from student table.
12. Display all those records of students whose course number is ‘CIS326’ from
Enrollment table.

13. To display all students that course number are in "CIS326", "NM204" or

"CS303" from Enrollment table.

14. To display all students that major are not in "English", "Art" or

"business" from student table.

15. To display all students where grade is “c” and courseno is “CIS326” from

Enrollment table.

16. To display all students where grade is “c” or grade is ”a” from

Enrollment table.

17. To display all students where Major is NOT "English " from student table.

18. To display all students where Major is “Business” and Status must be “1” OR “3”.

19. Display all records whose first name starting with "J" from student table.

20. Display all records whose first name ending with "y" from student table .

21. Display all records whose Instructor starting with "m" in any position.

22. Display all course title that have "a" in the second position.

23. Display all students with a lastName that starts with "J" and are at least 3
characters in length from student table.
Table Name:- Employee

Empid EmpName Department Cont_No EmailId EmpHeadId


101 Isha E-101 1234567890 [email protected] 105
102 Priya E-102 1234567890 [email protected] 103
103 Neha E-103 1234567890 [email protected] 101
104 Rahul E-104 1234567890 [email protected] 105
105 Abhishek E-105 1234567890 [email protected] 102

Table :- EmpDept
DeptHea
DeptId DeptName Dept_off
d
E-101 HR Monday 105
E-102 Development Tuesday 101
E-103 House Keeping Saturday 103
E-104 Sales Sunday 104
E-105 Purchase Tuesday 104

Table :- EmpSalary

EmpId Salary IsPermanent


101 2000 Yes
102 10000 Yes
103 5000 No
104 1900 Yes
105 2300 Yes

Table :- Project

ProjectId Duration
p-1 23
p-2 15
p-3 45
p-4 2
p-5 30

Table :-
EmpProject
EmpId ProjectId StartYear EndYear
101 p-1 2010 2010
102 p-2 2010 2012
103 p-3 2013
104 p-4 2014 2015
105 p-5 2015

Query:

1. Create all tables using constrains.

2. Insert all records.

3. To add columns Emp_Contactno in employee table.

4. To delete columns Emp_Contactno in employee table.

5. Update the Dept_off=”Wednesday” for Employee whose ID number is E-102 in the table.

6. Display the records of employee whose salary is more than 2000.

7. To add columns emp_age in employee table[ add constraint age>=18].

8. Display all those records whose department name is HR.


9. Display all those records of students whose project id is ‘p-5’ .

10. Display all those records of employee whose employee id is ‘101’ from Employee
table.

11. Display all those records of employee whose department id is ‘E-103’.

12. To display all employee that projectid are in "p-1", "p-3" or


"p-5" from Employee project table.

13. To display all department name that are not in "E-101", "E-102" or

"E-105".

14. To display all project duration between 15 and 30.

15. Display all records whose name starting with "r".

16. Display all records whose department name ending with "t" .

17. Display all records whose department name starting with "L" in any position.

18. Display all employee name that have "s" in the second position.

19. To modified department name was ’sales’ and set it to a new name’hr’.

20. to find the details of all employee whose day_off is ‘monday’ or ‘Tuesday’.

SQL JOIN

1. Write a SQL query to display an employee name, employee email and


department name using employee and department tables.
2. Write a SQL query to display a employee email, employee contact no,
department off using employee and department tables whose the
department name is HR.
3. Write a SQL query to retrieve an All the records from employee and
department tables.
4. Write a SQL query to retrieve an employee name, employee salary,
department id, contact no, employee email and employee salary using
employee and employee salary tables.

5. Write a SQL query to display an employee name, contact no, email and
employee salary using employee and employee salary tables whose salary
is greater than 1000 and whose employee name starts with ‘N’.
6. Write a SQL query to display an employee email, employee contact no,
employee salary using Employee and employee salary tables.
7. Write a SQL query to display a project duration, start year, end year and
employee id using project and employee project tables.
8. Write a SQL query to display a start year, end year, employee id, project id,
duration using project and employee project tables whose start year from
2010.
9. Write a SQL query to display an employee email, employee contact no,
department off using employee and department tables whose the
department name is HR and Development.
10. Write a SQL query to find employee table to display an employee name,
employee email.

AIM: AGGREGATE FUNCTIONS ,GROUP BY, HAVING CLAUSE

Table-name: Order-details

ord_no purch_amt ord_date customer_id salesman_id


---------- ---------- ---------- ----------- -----------
70001 150.5 2012-10-05 3005 5002
70009 270.65 2012-09-10 3001 5005
70002 65.26 2012-10-05 3002 5001
70004 110.5 2012-08-17 3009 5003
70007 948.5 2012-09-10 3005 5002
70005 2400.6 2012-07-27 3007 5001
70008 5760 2012-09-10 3002 5001
70010 1983.43 2012-10-10 3004 5006
70003 2480.4 2012-10-10 3009 5003
70012 250.45 2012-06-27 3008 5002
70011 75.29 2012-08-17 3003 5007
70013 3045.6 2012-04-25 3002 5001

1. write a SQL query to calculate total purchase amount of all orders. Display total purchase
amount.
2. write a SQL query to calculate average purchase amount of all orders. Display average purchase
amount.
3. write a SQL query to count the number of unique salespeople. Display number of salespeople.
4. write a SQL query to find the maximum purchase amount.
5. write a SQL query to find the minimum purchase amount.
6. write a SQL query to count all the orders generated on '2012-08-17'. Display number of orders.

Table-name: customer_details

customer_id | cust_name | city | grade | salesman_id


-------------+----------------+------------+-------+-------------
3002 | Nick Rimando | New York | 100 | 5001
3007 | Brad Davis | New York | 200 | 5001
3005 | Graham Zusi | California | 200 | 5002
3008 | Julian Green | London | 300 | 5002
3004 | Fabian Johnson | Paris | 300 | 5006
3009 | Geoff Cameron | Berlin | 100 | 5003
3003 | Jozy Altidor | Moscow | 200 | 5007
3001 | Brad Guzan | London | | 5005

1. write a SQL query to find the highest grade of the customers for each of the city. Display city,
maximum grade.
2. write a SQL query to count the number of customers. Display number of customers.
3. write a SQL query to find the number of customers who got at least a gradation for his/her
activity.
4. write a SQL query to find the highest grade of the customers for each of the city. Display city,
maximum grade.
5. write a SQL query to find the highest purchase amount ordered by each customer. Display
customer ID, maximum purchase amount

Table-name: SALESMAN_details

salesman_id | name | city | commission


-------------+------------+----------+------------
5001 | James Hoog | New York | 0.15
5002 | Nail Knite | Paris | 0.13
5005 | Pit Alex | London | 0.11
5006 | Mc Lyon | Paris | 0.14
5007 | Paul Adam | Rome | 0.13
5003 | Lauson Hen | San Jose | 0.12

Queries: (Use any table from above to solve following queries)


1. write a SQL query to count number of orders by the combination of each order date and
salesperson. Display order date, salesperson id
2. write a SQL query to find the highest purchase amount ordered by each customer on a
particular date. Display , order date and highest purchase amount.
3. write a SQL query to find the highest purchase amount on '2012-08-17' by each salesperson.
Display salesperson ID, purchase amount.
4. write a SQL query to find highest order (purchase) amount by each customer in a particular
order date. Filter the result by highest order (purchase) amount above 2000.00. Display
customer id, order date and maximum purchase amount.
5. write a SQL query to find the maximum order (purchase) amount by each customer. The
customer ID should be in the range 3002 and 3007(Begin and end values are included.). Display
customer id and maximum purchase amount.

You might also like