ANSWER
1. CHAR is a fixed-length data type; VARCHAR is a variable-length data type.
2. [Link]()
3. A Primary Key is a column (or set of columns) that uniquely identifies each row in a
table and cannot contain NULL values.
4. To save all transactional changes permanently to the database.
5. fetchone()
6. DESCRIBE STUDENT; or DESC STUDENT;
7. NULL cannot be compared with =. Correct: SELECT * FROM EMP WHERE SALARY IS
NULL;
8. Ascending (ASC).
9. COUNT(column_name)
SECTION B (2 Marks Each)
11. DELETE: DML command, removes specific or all rows, can be rolled back.
o DELETE FROM Student WHERE Roll=1;
DROP: DDL command, removes the entire table structure and data from the database.
o DROP TABLE Student;
12. % matches any number of characters (zero or more). _ matches exactly one
character.
13. A Cursor acts as a control structure that enables traversal over the records in a result
set. It executes SQL queries and fetches data.
14. Python
15. import [Link]
con = [Link](host="localhost", user="root", password="pass",
database="School")
16. WHERE is used to filter rows before grouping. HAVING is used to filter groups after
the GROUP BY clause has been applied.
17. SELECT * FROM LIBRARY WHERE PRICE BETWEEN 300 AND 500;
18. Foreign Key: A column that creates a link between two tables (refers to a Primary Key
in another table). Candidate Key: Any column that has the potential to become a
Primary Key.
19. fetchall(): Fetches all remaining rows of a query result. rowcount: Returns the
number of rows affected by the last executed SQL statement.
20. ALTER TABLE MOVIES ADD Rating INT;
21. It is a set of rules that ensures relationships between tables remain consistent (e.g.,
you cannot delete a record if its Primary Key is being used as a Foreign Key in another
table).
SECTION C (4 Marks Each)
21. PRODUCT Queries:
o a) SELECT PNAME, PRICE FROM PRODUCT ORDER BY PRICE DESC;
o b) SELECT COUNT(*) FROM PRODUCT WHERE COMPANY = 'HUL';
o c) UPDATE PRODUCT SET PRICE = PRICE + (PRICE * 0.10);
o d) SELECT MAX(PRICE), MIN(PRICE) FROM PRODUCT;
22. Python Program:
Python
import [Link]
db = [Link](host="localhost", user="root", passwd="password",
database="test")
cur = [Link]()
eid = int(input("Enter ID: "))
nm = input("Enter Name: ")
sal = float(input("Enter Salary: "))
query = "INSERT INTO EMPLOYEE VALUES(%s, %s, %s)"
[Link](query, (eid, nm, sal))
[Link]()
print("Record Inserted")
[Link]()
23. Constraints:
o NOT NULL: Ensures a column cannot have a NULL value. Name VARCHAR(20)
NOT NULL
o UNIQUE: Ensures all values in a column are different. Email VARCHAR(30)
UNIQUE
o DEFAULT: Provides a default value if none is specified.
City VARCHAR(20) DEFAULT 'Delhi'
o CHECK: Ensures values satisfy a specific condition. Age INT CHECK (Age >= 18)
24. STAFF Queries:
o a) SELECT DEPT, AVG(SALARY) FROM STAFF GROUP BY DEPT;
o b) SELECT NAME FROM STAFF WHERE NAME LIKE 'A%' OR NAME LIKE '%a';
o c) SELECT SUM(SALARY) FROM STAFF WHERE DEPT = 'IT';
o d) SELECT * FROM STAFF WHERE SALARY > 50000;
25. Fetch Program:
Python
import [Link]
con = [Link](host="localhost", user="root", password="pw",
database="db")
cur = [Link]()
[Link]("SELECT * FROM CLIENT WHERE City = 'Delhi'")
data = [Link]()
for row in data:
print(row)
[Link]()
Answers: 1. | Name | PName | | :--- | :--- | | S. Sharma | Aman | | V. Kohli | Rahul | 2. 3 3.
92 65 4. | Name | | :--- | | V. Kohli |
Answers: 1. | Department | SUM(Charges) | | :--- | :--- | | Surgery | 8500 | | ENT | 3800 |
2. | UPPER(Name) | | :--- | | ZAYAN | | MARY | 3. | Name | | :--- | | Arpit | | Ken | 4. |
SUBSTR(Department, 1, 3) | | :--- | | Sur | | Sur |