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

Assignment_12_SQL(25)

The document outlines an assignment focused on Database Management Systems (DBMS) and SQL syntax, covering definitions, key concepts, and commands related to databases. It includes tasks such as defining terms, explaining keys, writing SQL queries for creating and manipulating tables, and performing various data retrieval operations. The assignment is structured into chapters with specific questions and examples to demonstrate SQL functionalities.

Uploaded by

neelufar.arif
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Assignment_12_SQL(25)

The document outlines an assignment focused on Database Management Systems (DBMS) and SQL syntax, covering definitions, key concepts, and commands related to databases. It includes tasks such as defining terms, explaining keys, writing SQL queries for creating and manipulating tables, and performing various data retrieval operations. The assignment is structured into chapters with specific questions and examples to demonstrate SQL functionalities.

Uploaded by

neelufar.arif
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

COMPUTER SCIENCE – ASSIGNMENT

UNIT- 3
CHAPTER: DBMS & SQL SYNTAXES
1 Define the following terms:
i) DBMS ii) Data integrity iii) Data Reliability iv)SQL
v) Referential Integrity
2. Define the following terms: To view all the values from a table
i) Degree ii) Cardinality iii) Tuple
iv) Relation v) Domain vi) Attribute vii) Keys
3 Explain the following keys:
i) Candidate key ii) Primary key iii) Alternate key iv) Foreign key
4 Write about DDL & DML commands
5 Write the syntax and eg for the following:
i) To create database ii) To open a database
ii) To view the databases iv) To delete the database
iv) To create a table v)To view tables in the database
v) To describe table properties vii)To delete the table

6 Write the syntax and eg for the following:


i) To insert values to the table to all columns/fields?
ii) To insert values to the specified columns/fields?
iii) To view all the values from a table
iv) To view the particular column To the table
v) To use the where clause
vi) To use where clause with logical operator
vii) To use the distinct keyword
viii) To use the between operator
ix) To use the in, not in operator
x) To use the LIKE operator
xi) To change the values in table using update

7 Write the syntax and eg for the following:


i) To use the primary key while creating a table
ii) To add the primary key in the existing table
iii) To use the foreign key
iv) To add the foreign key in the existing table
v) To delete a row from the table
vi) To add the constraints(unique,not null, default)
8 Write the syntax and eg for the following:
i) To add the column using alter
ii) To delete the column using alter
iii) To change the column name using alter
iv) To change the column datatype using alter
9 Write the syntax and eg for the following:
i) To use group by function
ii) To use order by clause
iii) To use having clause
iv) To use aggregate function

10 Write the syntax and eg for the following:


i) Natural join
ii) Equi join
iii) Cartesian product
CHAPTER: SQL QUERY
1 A department is considering to maintain their worker data using SQL to store the data. As a
database administer, Karan has decided that :
Name of the database – Department Name of the table - WORKER
The attributes of WORKER are as follows:
WORKER_ID - character of size 3 , FIRST_NAME – character of size 10
LAST_NAME– character of size 10, SALARY - numeric
JOINING_DATE – Date, DEPARTMENT – character of size 10
I) Write the query to create the table based on the above specification
II)Identify the attribute best suitable to be declared as a primary key
Write an appropriate query for the following
III) Karan wants to increase the size of the FIRST_NAME column
from 10 to 20 characters..
IV) Karan wants to remove all the data from table WORKER from the database
Department.
2 Write SQL query to create a table ‘Inventory’ with the following structure:
Field Type Constraint

MaterialId Integer Primary key


Material Varchar(50) NOT NULL
Category Char DEFAULT E
DatePurchase Date

4 Consider the table Flight given below, write command in SQL for (i) to (iv) and output for
(v) to (viii)

i)To display Flight flying between Varanasi and Nepal.


ii) To display the different Origin of Flights.
iii) To display list of flights in descending order of Rate.
iv) To display flight details of the flight whose flightdate is after Jan 2008.
v) SELECT Flight_No, Destination FROM Flight WHERE Destination LIKE ‘_u%’;
vi) SELECT Origin, COUNT(*) FROM Flight GROUP BY Origin;
vii) SELECT Origin, Destination FROM Flight WHERE seats>400;
viii) SELECT SUM(Rate),MAX( Seats) FROM Flight
5 Consider the following table ‘Transporter’ that stores the order details about items to be
transported. Write SQL comma
nds for the statements (i) to (viii).
Table: TRANSPORTER

(i)To display names of drivers and destination city where TELEVISION is being
transported.
(ii) To display driver names and destinations where destination is not MUMBAI.
(iii) To display the names of destination cities where items are being transported. There
should be no duplicate values.
(iv) To display details of rowsthat have some value in DRIVERGRADE column.
(v) To display names of drivers, names of items and travel dates for those items that are
being transported on or before 1st April 2019.
(vi) To display the number of drivers who have ‘MOHAN’ anywhere in their names.
(vii) To display the names of drivers, item names and travel dates in alphabetic
(ascending) order of driver names.
(viii) To display names of drivers whose names are three characters long.
6 Consider the table given below. Write SQL queries for (i) to (vii).
Columns REGID stores Registration Id, PREWEIGHT stores weight of the person before
joining
Gym, CURRWEIGHT stores current weight, DOJ stores Date of Joining, BRANCH stores
the
branch of Gym where the person has enrolled.
(i) To display names of members along with their previous and current weights who are in
Model Town branch.
(ii) To display all names of members, previous weight, current weight, Change in weight
(i.e.how much increase from previous weight or decrease from previous weight, Decrease
will be displayed with negative sign)
(iii) To display BRANCH wise count of members in the Gym. (i.e. display the BRANCH
and number of members in each BRANCH)
(iv) To display names and date of joining of all the members who joined in the year 2018.
(v) To display Names and Current weight of all the members in descending order of Current
Weight.
(vi) To display the names and date of joining of male members who have joined after 27th
September 2018.
(vii) To display names and date of joining of members who have their names starting with
‘S’and ending with ‘a’.
7

(a) To display all information about the CUSTOMERs whose NAME starts with
'A'.
(b) To display the NAME and BALANCE of Female CUSTOMERs (with GENDER as
'F') whose TRANSACTION Date (TDATE) is in the year 2019.
(c) To display the total number of CUSTOMERs for each GENDER.
(d) To display the CUSTOMER NAME and BALANCE in ascending order of GENDER.
(e) To display CUSTOMER NAME and their respective INTEREST for all
CUSTOMERs where INTEREST is calculated as 8% of BALANCE.
8
Write SQL queries for a to d, which are based on the tables :
CUSTOMERS and PURCHASES then write the outputs for (i) to (iii)
a) To display details of all CUSTOMERS whose CITIES are
neither Delhi nor Mumbai.
b) To display the CNAME and CITIES of all CUSTOMERS in
ascending order of their CNAME.
c) To display the number of CUSTOMERS along with their
respective CITIES in each of the CITIES.
d) To display details of all PURCHASES whose Quantity is
more than 15.
9

10

(i)SELECT PRODUCTNAME, COUNT(*)FROM COMPANY GROUP BY


PRODUCTNAME HAVING COUNT(*)> 2;
(ii) SELECT NAME, PRICE, PRODUCTNAME FROM COMPANY C,
CUSTOMER CT WHERE C.CID = CU.CID AND C_NAME = 'SONY';
(iii) SELECT DISTINCT CITY FROM COMPANY;
(iv) SELECT * FROM COMPANY WHERE C_NAME LIKE '%ON%';
11
(i) To display details of all Trains which Start from New Delhi.
(ii) To display the PNR, PNAME, GENDER and AGE of all
Passengers whose AGE is below 50.
(iii) To display total number of MALE and FEMALE Passengers.
(iv) To display details of all Passengers travelling in Trains
whose TNO is 12015.
(v) SELECT MAX (TRAVELDATE), MIN(TRAVELDATE) FROM
PASSENGERS WHERE GENDER = 'FEMALE';
(vi) SELECT END, COUNT(*) FROM TRAINS
GROUP BY END HAVING COUNT(*)>1;
(vii) SELECT DISTINCT TRAVELDATE FROM PASSENGERS;
(viii) SELECT TNAME, PNAME FROM TRAINS T, PASSENGERS P
WHERE T.TNO = P.TNO AND AGE BETWEEN 50 AND 60;

You might also like