Which SQL constraint ensures that all values in a column are distinct?
(a) NOT NULL (b) UNIQUE (c) DEFAULT (d) PRIMARY KEY
The data type used for storing dates in 'YYYY-MM-DD' format in MySQL is:
(a) CHAR (b) VARCHAR (c) DATE (d) INT
Assertion (A): CHAR(n) is a fixed-length data type while VARCHAR(n) is variable-length.
Reason (R): In CHAR(n), unused spaces are padded with spaces on the right.
Choose the correct option:
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true.
Which clause is used to eliminate duplicate rows from the result of a SELECT query?
(a) WHERE (b) DISTINCT (c) ORDER BY (d) GROUP BY
The statement used to permanently remove a table from the database is:
(a) DELETE (b) DROP TABLE (c) ALTER TABLE (d) TRUNCATE
Assertion (A): A foreign key in one table refers to the primary key of another table.
Reason (R): Foreign key ensures referential integrity between relations.
Choose the correct option:
(a) Both A and R are true and R is the correct explanation of A.
(b) Both A and R are true but R is not the correct explanation of A.
(c) A is true but R is false.
(d) A is false but R is true.
Which function returns the number of characters in a given string?
(a) LENGTH() (b) MID() (c) ROUND() (d) NOW()
The clause used to group rows having the same values in a specified column is:
(a) WHERE (b) ORDER BY (c) GROUP BY (d) HAVING
Which operator is used to check for NULL values in a column?
(a) = NULL (b) IS NULL (c) LIKE (d) IN
The result of SELECT MOD(21,2); is:
(a) 0 (b) 1 (c) 10 (d) 21
SELECT UCASE("informatics practices"); SELECT LENGTH("Computer Science");ALTER TABLE GUARDIAN MODIFY GPhone CHAR(10) UNIQUE;SELECT PaymentMode, COUNT(*) FROM SALE GROUP BY PaymentMode HAVING COUNT(*) > 1; Write the complete sequence of SQL statements to:
- Create the database StudentAttendance.
- Create the three tables STUDENT, GUARDIAN and ATTENDANCE (with correct data types and constraints as given in Tables 9.3–9.5, including composite primary key and foreign keys).
- Insert the sample records shown in Tables 9.6 and 9.7.
(Use proper syntax and termination with semicolon.)
Consider the following query on the EMPLOYEE table:
SELECT DeptId, AVG(Salary) FROM EMPLOYEE GROUP BY DeptId HAVING AVG(Salary) > 30000 ORDER BY DeptId;
Perform a dry-run and prepare a trace table showing step-by-step processing of the GROUP BY and HAVING clauses. Show final output.
Explain the working of the three set operations UNION, INTERSECT and MINUS with the help of the DANCE and MUSIC relations (Tables 9.18–9.19). Write one SQL query for each operation using the given relations.
Consider the four relations INVENTORY, CUSTOMER, SALE and EMPLOYEE (Tables 9.9–9.12).
Sub-questions:
(a) Write a query to display CarId, CarName and the rounded GST (12% of Price) for all cars.
(b) Write a query to find the total commission earned by each employee (EmpID) from the SALE table.
(c) Write a query to display details of all cars whose model name contains the substring “1.2”.
(d) Write a query to display the month name in which the maximum number of cars were sold.
Consider the two relations UNIFORM and COST (Tables 9.25–9.26) with UCode as the common attribute.
Sub-questions:
(a) Write a query to display UCode, UName, Size and Price of all uniforms using an explicit JOIN.
(b) Write a query to display only those records where the uniform colour is “White”.
(c) Write a query using NATURAL JOIN and state how it differs from the JOIN in (a).
(d) Write a query to find the average price of uniforms of each size.
column BETWEEN low AND high. CREATE TABLE STUDENT (RollNumber INT PRIMARY KEY, SName VARCHAR(20) NOT NULL, SDateofBirth DATE NOT NULL, GUID CHAR(12) FOREIGN KEY REFERENCES GUARDIAN(GUID)); SELECT EmpNo, Ename FROM EMPLOYEE WHERE Salary BETWEEN 20000 AND 50000 ORDER BY Salary; ALTER TABLE GUARDIAN ADD UNIQUE(GPhone); (after ensuring datatype). (Correct queries for each sub-part using appropriate clauses/functions from the chapter, with brief explanation of output.)
All questions are answerable from the NCERT chapter text. Reviewed by GFIS faculty.