Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
31 views

SQL Table

Uploaded by

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

SQL Table

Uploaded by

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

SQL -1

TABLE : EMPLOYEE
Column name Datatype Size Constraint
Ecode Integer 5 Primary Key
Name Varchar 20 Can never to left empty
Dept Varchar 20 Default “HRA”
Date_of_birth Date
Gender Char 1
Designation Varchar 20
Salary Integer 10

Ecode Name Dept Date_of_birt Gende Designation Salary


h r
101 Sunita Sales 06-06-1995 F Manager 25000
102 Neeru Office 05-07-1993 F Clerk 12000
103 Raju Purchase 05-06-1994 M Manager 26000
104 Neha Sales 08-08-1995 F Accountant 18000
105 Nishant Office 08-10-1995 M Clerk 10000
106 Vinod Purchase 12-12-1994 M Clerk 10000

i. Display the list of all the databases of your system.


ii. Create a database with name XI.
iii. Open the database XI.
iv. Display the name of all tables in database XI.
v. Write command to create EMPLOYEE table.
vi. Display the structure of EMPLOYEE table.
vii. Insert the above data in EMPLOYEE table.
viii. Display the detail of all employees of EMPLOYEE table.
ix. Display Name, Salary and gender of all employees from EMPLOYEE table.
x. Display the detail of all employees who are working as ‘Clerk’ or ‘Manager’.
xi. Add a column Contact_No varchar(30) in EMPLOYEE table.
xii. Increase the salary of all female employees by 10%.
xiii. Remove the detail of all employees whose salary is in between 12000 and 20000.
xiv. Display name, designation of employees whose name starts with “N” letter.
xv. Display the detail of all employees in ascending order of their salary.
SQL - 2

Consider the following table Product. Write SQL queries for the following statements

TABLE : PRODUCT

P_ID PRODUCTNAME MANUFACTURER PRICE QUANTITY


TP01 Talcom Powder Ponds 40 50
TP02 Talcom Powder Johnson 80 60
FW06 FaceWash Lux 45 20
BS01 Bath Soap Patanjali 55 40
SH06 Shampoo Ponds 120 10
FW12 Face Wash Patanjali 90 20

1. Create the above table with P_ID as primary key.


2. Insert all data.
3. Display all records.
4. Add a new column Amount.
5. Update Amount field by Price * Quantity.
6. Display all data in ascending order of amount.
7. Display Product name, Amount, discount offered where discount is 10% of Amount.
8. Increase the price of Lux manufacturer by 10%.
9. Display total number of manufacturers.
10. Display maximum and minimum quantities.
11. Display names of products whose manufacturer name starts with P.
12. Display names of products whose manufacturer is either Lux or Ponds.
13. Display the structure of the table.
14. Display total amount.
15. Delete the record whose P_id is ending with 6.
SQL - 3

Consider the table STOCK given below

Write SQL commands to:


a. Display the average amount of each Loan Type
b. Display details in the increasing order of the Interest
c. Display the total amount from each loan type with interest greater than 9
d. Display maximum and minimum Amount of all account holder whose name starts with A.
e. Display sum of amount of Acc_Nos HD1003, HD1006 and HD1008.
f. Display names of account holders whose amount >=50000 and <=100000.
SQL - 4

Table : TRAINER
TID TNAME CITY HIREDATE SALARY
101 Sunaina Mumbai 1998-10-15 90000
102 Anamika Delhi 1994-12-24 80000
103 Deepti Chandigarh 2001-12-21 82000
104 Meenakshi Delhi 2002-12-25 78000
105 Richa Mumbai 1996-01-12 95000
106 Maniprabha Chennai 2001-12-12 69000

Table : COURSE
CID CNAME FEES STARTDATE TID
C201 AGDCA 12000 2018-07-02 101
C202 ADCA 15000 2018-07-15 103
C203 DCA 10000 2018-10-01 102
C204 DDTP 9000 2018-09-15 104
C205 DHN 20000 2018-08-01 101
C206 O LEVEL 18000 2018-07-25 105

Write SQL queries for the following:

1. Create the tables Trainer (TID is primary key) and Course (CID is primary key)
2. Insert the given data into the respective tables.
3. Display the structure of the tables.
4. Display the Trainer Name, City & Salary in descending order of their Hiredate.
5. To display the TNAME and CITY of Trainer who joined the Institute in the month of December
2001.
6. To display TNAME, HIREDATE, CNAME, STARTDATE from tables TRAINER and COURSE
of all those courses whose FEES is less than or equal to 10000.
7. To display number of Trainers from each city.
8. To increase the fees of the course by 10% where the fee >=5000 and <=12000.
9. Display the Trainer Name, City, hiredate and Salary of the trainers whose name starts with M.
SQL - 5
Consider the following tables SUBJECT and TEACHER.

Table – Subjects Table - Teachers


Code Title Mark_Th Mark_pr TCode Name SubCode
301 English 80 20 1 Prakash Jain 301
041 Mathematics 80 20 2 S Sarangi 041
083 Comp Science 70 30 3 T G Mathew 043
042 Physics 70 30 4 Sutapa Moitra 301
043 Chemistry 70 30 5 Vinod Sharma 042
048 Painting 60 40 6 Victor M 083
7 Arjun Sharma 043

Write SQL commands for the following statements:


1. Create the tables Subjects (Primary key Code) and Teachers (Primary key TCode).
2. Insert the given data.
3. To display the names of all the subjects for which practical marks are 0.
4. To display the total number of teachers in each subject separately.
5. To display the names of all the teachers in the ascending order of the Sub_Code.
6. To display each subject’s details along with Total_Marks in each subject from the table SUBJECTs
where (Total_Marks = Marks_Theory + Marks_Practical).
7. Write SQL statement to display each teacher’s name along with his/her respective subject name
from the tables TEACHER and SUBJECT.
SQL : 6
Create TEACHER table with the following structure:
Column name Datatype Size Constraint
Tno Integer 5 Primary Key
Tname Varchar 20 Can never to left empty
Subject Varchar 20 Default “Science”
Salary Integer 10

Create STUDENT table with following structure


Column name Datatype Size Constraint
Rollno Integer 5 Primary Key
Sname Varchar 20 Can never to left empty
Gender Char 1 Default “F”
Marks Integer 3
Tno Integer 5 Reference key from Teacher table

i. Create Teacher and Student tables.


ii. Display Teacher name and student name from teacher and student tables.

iii. Remove the details of all students whose marks are below 33.

iv. Display subject and number of teachers teaching the same subject.

v. Insert a record in the teacher table.

vi. Display the detail of all students in ascending order of their marks
SQL : 7
Table: STORE

SNO SNAME AREA


S01 ABC Computronics GK II
S02 ALL Infotech Media CP
S03 Tech Shoppe Nehru Place
S04 Geeks Tecno Soft Nehru Place
S05 Hitech Tech Store CP

Table: ITEM

INO INAME PRICE SNO


T01 Mother Board 12000 S01
T02 Hard Disk 5000 S01
T03 Keyboard 500 S02
T04 Mouse 300 S01
T05 Mother Board 400 S03
T06 Key Board 400 S03
T07 LCD 6000 S04
T08 LCD 5500 S05
T09 Mouse 350 S05
T10 Hard Disk 4500 S03

a. Create STORE and ITEM tables, where SNO is foreign key.


b. Insert data in the above defined tables.
c. To display IName and Price of all the Items in ascending order of their price.
d. To display SNo and SName of all Stores located in CP.
e. To display Minimum and Maximum Price of each IName from the table Item.
f. Decrease the price of all items by 5% whose name starts with ‘K’ and ends with ‘d’.
g. To display IName, Price of all items and their respective SName where they are available.
SQL : 8

Table: SUPPLIER

SUPCODE SNAME CITY


S01 GET ALL INC KOLKATA
S02 EASY MARKET CORP DELHI
S03 DIGI BUSY GROUP CHENNAI

Table: PRODUCT
PID PNAME QTY PRICE COMPANY SUPCODE
101 DIGITAL CAMERA 14X 120 12000 RENIX S01
102 DIGITAL PAD 11i 100 2200 DIGI POP S02
103 PEN DRIVE 16 GB 500 1100 STOREKING S01
104 LED SCREEN 32 70 28000 DISPEXPERTS S02
105 CAR GPS SYSTEM 60 12000 MOVEON S03

1. Create Products and suppliers tables, where SUPCODE is foreign key..


2. To display the details of all the products in the ascending order of the product names (i.e.,
PNAME).
3. To display the product name and the price of all those products, whose price is in the range of
10,000 and 15,000 (both values inclusive).
4. To display the names of those suppliers, who are either from DELHI or from CHENNAI.
5. To display the names of the companies and the products in the descending order of the company
names.
SQL : 9
TABLE : SENDER

SenderID SenderName SenderAddress SenderCity

ND01 R Jain 2, ABC Appts New Delhi

MU02 H Sinha 12, Newtown Mumbai

MU15 S Jha 27/A, Park Street Mumbai

ND50 T Prasad 122-K, SDA New Delhi

TABLE : RECIPIENT

RecID SenderID RecName RecAddress RecCity

KO05 ND01 R Bajpayee 5, Central Avenue Kolkata

ND08 MU02 S Mahajan 116, A Vihar New Delhi

MU19 ND01 H Singh 2A, Andheri East Mumbai

MU32 MU15 P K Swamy B5, CS Terminus Mumbai

ND48 ND50 S Tripathi 13, B1 D, MayurVihar New Delhi

a. Create sender and recipient tables where SENDERID is foreign key.


b. Insert data as given above.
c. To display the names of all Senders from Mumbai.
d. To display the ReclD, SenderName, SenderAddress, RecName, RecAddress for every Recipient.
e. To display Recipient details in ascending order of RecName.
f. To display the number of Recipients from each city.

You might also like