SQL Query X
SQL Query X
QUESTIONS
1. What is a relation? What is the difference between a tuple and an
attribute?
Ans A relation is table having atomic values, unique rows and unordered rows and columns.
A row in a relation is known as tuple whereas a column of a table is known as an attribute .
2. What is primary key in a table?
Ans A Primary Key is a set of one or more attributes that can be uniquely identify tuples
within the relation.
3. What is data redundancy? What are the problems associated with it?
Ans Duplication of data is data redundancy. It leads to the problems like wastage of space
and data inconsistency.
4. Define the following terms: (i) Degree (ii) Cardinality.
Ans (i) Degree: The numbers of attributes (columns) in a relation determine the degree of a
relation.
(ii) Cardinality: The number of tuples (rows) in a relation is called the cardinality of the
relation.
5. What are views? How are they useful?
Ans A view is a virtual table that does not really exist in its own right but it instead derived
from one and more underlying base table(s). The view is kind of table whose contents are
taken upon other tables depending upon a given query condition. No stored file is created to
store contents of a view rather its definition is stored only.
The usefulness of views lies in the fact that they provide an excellent way to give people
access to some but not all of the information in a table.
6. Differentiate between Candidate Key and Primary Key in context of
RBDMS.
Ans Candidate Key. A candidate key is the one that is capable of becoming primary key. i.e.,
a field or attribute that has unique value for each row in the relation.
Primary Key is a designed attribute or a group of attributes whose values can uniquely
identify the tuples in the relation.
3. Create a table with the under mentioned structure (Table name is DEPT)
DeptNo NUMBER(2)
DeptNam CHAR(12)
Location CHAR(12)
Ans :-
CREATE TABLE Dept
( DeptNo NUMBER(2) NOT NULL PRIMARY KEY,
DeptNam CHAR(12),
Location CHAR(12);
4. Create a table called PROJECT with the columns specified below.
ProjId NUMBER(4)
ProjDesig CHAR(20)
ProjStartDT DATE
ProjEndDT DATE
BudgetAmount NUMBER(7) 0
MaxNoStaff NUMBER(2)
Ans :-
CREATE TABLE Project
( ProjId Number(4) NOT NULL PRIMARY KEY,
ProjDesig Char (20) NOT NULL,
ProjStartDT Date,
ProjEndDT DATE,
BudgetAmount Decimal(7,2) default=0,
MaxNoStaff Number(2) );
6. Insert a record with suitable data in the table EMP, having system date as the Hiredate.
Ans :- Date ( ) function gives the system date.
INSERT INTO Emp VALUES (3008, 18, “XAVIER”, “Manager”, Date( ), 3250, NULL);
(a) List the names of those students who have obtained DIV 1 sorted by NAME.
(b) Display a report, listing NAME, STIPEND, SUBJEZCT and amount of stipend received in a
year assuming that the STIPEND is paid every month.
(c) To count the number of students who are either PHYSICS or COMPUTER SC
graduates.
(d) To insert a new row in the GRADUATE table:
11, “KAJOL”, 300, “COMPUTER SC”, 75, 1
(e) Give the output of following SQL statement based on table GRADUATE:
(I) Select MIN(AVERAGE) from GRADUATE where SUBJECT= “PHYSICS”;
(II) Select SUM(STIPEND) from GRADUATE where DIV=2;
(III) Select AVG(STIPEND) from GRADUATE where AVERAGE>=65;
(IV) Select COUNT(distinct SUBJECT) from GRADUATE;
(f) Assume that there is one more table GUIDE in the database as shown below:
Table: GUIDE
MAINAREA ADVISOR
PHYSICS VINOD
COMPUTER SC ALOK
CHEMISTRY RAJAN
MATHEMATICS MAHESH
What will be the output of the following query?
SELECT NAME, ADVISOR FROM GRADUATE, GUIDE WHERE SUBJECT =” MAINAREA”
Ans:-
(a) Select Name From GRADUATE Where DIV = 1 Order by Name;
(b) Select Name, stipend, subject, stepend * 12 From GRADUATE
(c) Select count (*) From GRADUATE Where subject IN (“PHYSICS”, “COMPUTER SC”);
(d) Insert into GRADUATE Values (11, “KAJOL”, 300, “COMPUTER SC”, 75, 1);
(e) (i) 63 (ii) 1000 (iii) 450(iv) 4
(f)
KARAN VINOD
DIVAKAR ALOK
DIVYA RAJAN
ARUN VINOD
SABINA MAHESH
JOHN RAJAN
ROBERT VINOD
RUBINA MAHESH
VIKAS ALOK
MOHAN MAHESH
9. “ABC” Event Management Company requires data of events that are to be organized. Write
SQL query to create a table ‘Event’ with the following structure :
Ans: Create table Event(EventID Int Primary Key,Event Varchar(50),DateEvent Date,NumPerformers Int);
10. Suggest her suitable command for the following purpose:
I. To display the list of the database already existing in MySQL.
II. To use the database named City.
III. To remove the pre-existing database named Clients.
IV. To remove all the records of the table named “Club” at one go along with its structure
permanently.
Ans :
i. Show databases;
ii. Use City;
iii. Drop database Clients;
iv. Drop table Club;