Sie sind auf Seite 1von 8

I.

Create the following tables:


TABLE : STUDENT
COLUMN NAME DATA TYPE CONSTRAINTS
Roll_no Number(5) Primary Key
Name Varchar(20) Not null
Dept_name Varchar(20)
Gender Varchar(2)
Contact_no Number(10)

Write SQL queries for the following


1) Insert 5 records to the table
2) Display details of all students
3) Display details of all Female students
4) Find rollno, name of all students from a particular department
5) Find name and contactno of all Male students

2.Create the following tables:


TABLE :BOOK
COLUMN NAME DATA TYPE CONSTRAINTS
BookID Varchar(6) Primary Key
BookName Varchar(15) Not null
Author_Name Varchar(15)
Publisher Varchar(20)
Unit_price Number(8,2) Not null,cannot be zero
Quantity Number(3)
Write SQL queries for the following
1) Insert 5 records to the table
2) Display details of all books
3) Display details of all books from a particular Author
4) Find BookName, Price of all books from a particular Publisher
5) Find BookID, Bookname and Quantity of books whose price is between 200
and 500.
6) Find the details of book from a particular publisher and unit_price above 500.
7) Find the Totalprice of each book. (Totalprice=unitprice* quantity)

SQL LAB
Set I
3.Create the following tables:
TABLE : STUDENT
COLUMN NAME DATA TYPE CONSTRAINTS
Roll_no Number(5) Primary Key
Name Varchar(20) Not null
Dept_id Number(5) Foreign Key
Gender Varchar(2)
Contact_no Number(10)

TABLE : DEPARTMENT
COLUMN NAME DATA TYPE CONSTRAINTS
Dept_id Number(5) Primary Key
Dept_name Varchar(10) Not null

Write SQL queries for the following


1. a. Insert 5 records in each table
b. Update the contact number of student with Roll_no 005
2. a. Display the data of female students in alphabetical order.
b. Find the number of students in Electrical Department
c. Find department id and no. of students from each deptid
d. Find rollno ,name and department name of all students
e. Find name and contactno of all male students from bca department.

4.Create the following tables:


TABLE: CUSTOMER
Column name Data type Size Constraints
Cust_id Varchar 10 Primary Key
Fname Varchar 25 Not Null
Lname Varchar 25
Area Varchar 10 Kottayam ,Kollam, Kochi
Phone_number Numeric 15

TABLE : INVOICE

Column Name Data type Size Constraints

Inv_no Varchar 20 Primary Key

Cust_id Varchar 10 Foreign Key


Issue_date Date

Write SQL queries for the following:


1. a. Insert 5 records in each table
b. Change the issue date to 24/7/08 of cust_id 101
2. a. Find the issue date for the customer JOHNS.
b. List the customer name and invoice number of all customers
a. Find the lnames of all customers that begin with P or B.
b. List the customer details in the alphabetical order of their name

5.create table BOOK

Column name Data type constraints


bookid Varchar(6) primarykey
bookname Varchar(15) Not null
Author name Varchar(13)
Publisher Varchar(20)
Unit price Number(3)
quantity number

Write SQL queries for the following


1.Add a new field YEAR_OF_PUB
2.Delete the field Publisher from this table
3.Modify the Varchar size of Authour name to 20

6.create the following table


CUSTOMER
Column name Data type Constraints
Cus id Varchar(10) Primary key
Fname Varchar(15) Not null
lname Varchar(10)
address Varchar(20)
phone Number(10)
ORDER
Column name Data type constraints
Order id Varchar(10) Primary key
Order date date Not null
Order price Number(10) Not null
Order_qty Number(5)
Cus id Varchar(10) foreinkey

EMPLOYEE
Column name Data type constraints
Emcode Varchar(10) Primary key
Ename Varchar(15) Not null
Dname Varchar(10)
City Varchar(10)
Designation Varchar(20)
Salary Number(15)
bonus Number(7.2)

Write sql queries for the following

1.Add 5 records to each tables


2.Using the CUSTOMER table select cus id and name of customers from INDIA and
ENGLAND whose name start with A,B,C
3.From the EMPLOYEE table find the following
a) Average salary of employee
b) Maximum bonus
c) Total salary
d) Minimum salary
e) Total no. of employees
4. Find the sum of orders placed by customers (group by)
5.The name of employees with salary b/n 10000 and 25000
6. List the cities and count the employees from the cities where city has more than 2
Employees
7.Write a query to find customers who have place an order
8.Find the customers who not place an order

7.Create the following tables

CUSTOMER

Colum name Data type constraints


Cus id Varchar(10) Primary key
Cus-name Varchar(15) Not null
Acc no Number(20) Forien key
Place Varchar(10)
Phn no Number(10)
Gender Varchar(6)

ACCOUNT
Column name Data type constraints
Acc no Number(20) Primary key
Amount Varchar(20)

1.Insert 5 records to each table


2.Change the address of customer with cus id c345
3.
a) Find the customer details who have the highest balance in account
b)Sort the CUTOMER table on ascending order of Acc no
c)List the customers without phone number
d)List all cus id and name of all male customers belongs to to place name start with k and
end with y and balance amount > 5000
e) Find the customer name and a/c balance greater than average a/c balance
f) Find the average balance amount of customer based on city
4.update (increment) balance amount of all female account holder by 10%
5.Add RS.1000 to the balance amount of all customers from the place KOCHI
8.Create the following tables

PERSONS
Column name Data type Constraints
PID Numeric(5) Primary key
Fname Varchar(15) Not null
Lname Varchar(15)
Address Varchar(20)
City Varchar(10)

ORDER
Column name Data type Constraints
OID Numeric(5) Primary key
Order qty Numeric(5) Not null
Order date Date
PID Numeric(5) Foreign key

Write sql queries for the following


1. A)insert 5 records in each table
b) change the order quantity of the order no=578

2. A)Display the order details placed before 09-june-2013


b) List the order details of the customer johnson
c) List the name,address and city of Persons whose city is KOLLAM
d)List the details of persons in the alphabetical order of FNAME

9.Create tables with appropriate structure to store information about a number of items to be kept
in stock in a provision store and the details about the sales on a given day.Then write the needed
queries to
1. Inserting meaningful data into tables
2.Displaying the items in stock category wise
3. Details of sales made on a given day item wise
4. Display the sales bill with maximum amount on that day
10.Create the following tables

EMPLOYEE
Column name Data type Constraints
Eno Varchar(5) Primary key
Name Varchar(30) Not null
Designation Varchar(30) Trainee,team
member,team,head manager
Salary Number(7,2)

PROJECT
COLUMN NAME DATA TYPE CONSTRAINTS
PID Varchar(5) Primary key
Project name Varchar(25)
Eno Varchar(5) Foreign key

Write sql queries for the following

1. A)Insert 5 records in each tables


b) Update the designation of the employee named ALBERT
2.
a)Display the details of employees in alphabetical order of name
b)List the employee name along with the name of project assigned to him/her
c) List all those who are getting salary less than Rs.5000
d)Find the maximum ,minimum and average salary of employees
11.Create the following tables
CUSTOMER
COLUMN NAME Data type Constraint
Cno Varchar(6) Primary key
Cname Varchar(20) Not null
Address Varchar(20)
City Varchar(20)

SALES
COLUMN NAME Data type Constraint
ORDERNO Varchar(6) Primary key
ORDER DATE Date
Cno Varchar(6) Foreign key

Write sql queries for the following


1. A) Insert 5 records in each table
b) Update the address of customer john

2. A) Count the orders placed after 03-march-2012


b)find the number of customer jay

3. Create a view on cutomer table


4. Create a procedure for the following
a) Find the names of all customers , without repetition ,having A as first letter
in their names
b) Find the customers whose address iS NULL value

Das könnte Ihnen auch gefallen