Sample Paper Ip pt2 Answer
Sample Paper Ip pt2 Answer
1
Sr. No. Key DDL DML
Stands for DDL stands for Data Definition DML stands for Data Manipulation
1
Language. Language.
Usage DDL statements are used to create DML statement is used to insert,
2 database, schema, constraints, users, update or delete the records.
tables etc.
4. Consider the following table ‘BOOK’ and write output of the given queries 2
Ans i) SUM(PRICE)
500
ii) MIN(PRICE)
200
iii) MAX(PRICE)
600
iv) AVG(PRICE)
400
5. Consider the following table ‘CITY’ and write output of the given queries 2
CITYCODE CITYNAME
200 Jabalpur
110 Anuppur
275 Chhindwara
230 Balaghat
174 Dewas
i) SELECT * FROM CITY ORDER BY CITYNAME;
2
ii) SELECT * FROM CITY ORDER BY CITYCODE DESC;
i)
CITYCODE CITYNAME
110 Anuppur
230 Balaghat
275 Chhindwara
174 Dewas
200 Jabalpur
ii)
CITYCODE CITYNAME
275 Chhindwara
230 Balaghat
200 Jabalpur
174 Dewas
110 Anuppur
SECTION ‘B’
6. Differentiate between 6
a) Primary Key and Foreign Key
b) Degree and Cardinality of a relation
c) NOT NULL constraint and UNIQUE constraint
Ans a) A primary key is a column or a set of columns in a table whose values uniquely identify a row in
the table. ... A foreign key is a column or a set of columns in a table whose values correspond to
the values of the primary key in another table.
Primary Key never accepts null values whereas foreign key may accept multiple null values.
You can have only a single primary key in a table while you can have multiple foreign keys in a
table.
The value of the primary key can’t be removed from the parent table whereas the value of foreign
key value can be removed from the child table.
b) Degree is the number of attributes or columns present in a table. Cardinality is the number of
tuples or rows present in a table.
3
7. Write SQL command to create a table ‘TEACHER’ with the following specifications 3
Ans:
i) ALTER TABLE ITEM ADD(ItemPrice int);
ii) DESCRIBE ITEM
iii) ALTER TABLE ITEM DROP COLUMN ItemName;
SECTION ‘C’
9. Differentiate between 4
i) DROP TABLE and DELETE command in SQL
ii) CHAR and VARCHAR data type in SQL
Ans i) DELETE is used to delete one or several rows from the table.
DROP TABLE would remove the entire table from the database
DELETE is a DML command
DROP is a DDL command
ii) CHAR Datatype:
It is a datatype in SQL which is used to store character string of fixed length specified. If the length
of string is less than set or fixed length then it is padded with extra blank spaces so that its length
became equal to the set length. Storage size of CHAR datatype is of n bytes(set length). We should
use this datatype when we expect the data values in a column are of same length.
VARCHAR Datatype:
It is a datatype in SQL which is used to store character string of variable length but maximum of
set length specified. If the length of string is less than set or fixed length then it will store as it is
without padded with extra blank spaces. Storage size of VARCHAR datatype is equal to the actual
length of the entered string in bytes. We should use this datatype when we expect the data values
in a column are of variable length.
10. Explain 4
i) How can we insert a record in a table using SQL command? Give example.
ii) What is the use of ‘update’ command in SQL? Give example.
4
i) It is possible to write the INSERT INTO statement in two ways:
2. If you are adding values for all the columns of the table, you do not need to specify the column
names in the SQL query. However, make sure the order of the values is in the same order as the
columns in the table. Here, the INSERT INTO syntax would be as follows:
Example:
INSERT INTO Customers (CustomerName, ContactName, Address, City, PostalCode, Country)
VALUES ('Cardinal', 'Tom B. Erichsen', 'Skagen 21', 'Stavanger', '4006', 'Norway');
ii) the UPDATE command is used to update existing rows in a table.
The following SQL statement updates the first customer (CustomerID = 1) with a new contact
person and a new city.
Example
UPDATE Customers
SET ContactName = 'Alfred Schmidt', City= 'Frankfurt'
WHERE CustomerID = 1;
11. Consider the following table ‘CUSTOMER’ and write output of SQL queries for (i) to (iv) 4
(i)
CustomerName CustomerAge
Gagandeep 56
Ravindra 48
Shivram 61
5
(ii)
CustomerName CustomerCity
Ravindra Indore
Shivram Indore
(iii)
CustomerID CustomerName CustomerAge CustomerCity
4567 Hemraj 37 Balaghat
(iv)
CustomerCity
Durg
Indore
Balaghat
Jabalpur