Consider the following table STUDENT:
Table: STUDENT
Stud. | Name | Course | Result |
1101 | Anubhav Singh | BCom | Awaited |
1102 | Riya Sharma | BSc | Passed |
1103 | Kartikey Rana | BSc | Passed |
1104 | Archana Kapoor | BBA | Awaited |
1105 | Aarti Sharma | BCom | Awaited |
1106 | Sanchit Kumar | BCom | Passed |
Question 2(i)
What will be the query statement to insert a new record with Student id = 1107, name = Sumit Saxena, Course = BBA and result = passed
(A) sql = “INSERT INTO student (stuid, name, course, result) VALUES (‘1107’, ‘Sumit Saxena’, ‘BBA’, ‘Passed’)”
(B) sql = “INSERT INTO student VALUES (‘1107’, ‘Sumit Saxena’, ‘BBA’, ‘Passed’)”
(C) Both (a) and (b)
(D) None of these
Answer:
Checking the options
(A) sql = “INSERT INTO student (stuid, name, course, result) VALUES (‘1107’, ‘Sumit Saxena’, ‘BBA’, ‘Passed’)”
The query given above inserts the new record to table STUDENT.
(B) sql = “INSERT INTO student VALUES (‘1107’, ‘Sumit Saxena’, ‘BBA’, ‘Passed’)”
The query given above inserts the new record to table STUDENT.
(C) Both (a) and (b)
(D) None of these
Both option A and B , add the given record to the table.
So, the correct answer is (C)
Question 2(ii)
The following sql command has been given: Sql = “UPDATE student SET result = ‘Passed’ WHERE course = ‘BCom’ ” The result of which of the following STUID will be changed to “Passed”?
(A) 1101
(B) 1101, 1104
(C) 1101, 1105
(D) 1101, 1104, 1105
Answer:
Table STUDENT after executing the given query:
On comparing the updated table with the original table, it is clear that the value in the column result has been changed for 2 records , the records with Stud as 1101 and 1105 .
Checking the options:
- (A) 1101
- (B) 1101, 1104
- (C) 1101, 1105
- (D) 1101, 1104, 1105
So, the correct answer is (C)
Question 2(iii)
Consider the following code: sql = '''SELECT * from STUDENT''' cursor.execute(sql) result = cursor.fetchone(); print(result) What will be the output of the above code in reference to the STUDENT table?
(A) 1101, Anubhav Singh, BCom, Awaited
(B) 1106, Sanchit Kumar, BCom, Passed
(C) 1103, Kartikey Rana, BSc, Passed
(D) Both (A) and (B)
Answer:
The given code will display the first record from the table STUDENT as the fetchone( ) function retrieves one row from the result set.
Checking the options
- (A) 1101, Anubhav Singh, BCom, Awaited
- (B) 1106, Sanchit Kumar, BCom, Passed
- (C) 1103, Kartikey Rana, BSc, Passed
- (D) Both (A) and (B)
In the options given above, option A is the first record of the table STUDENT.
So, the correct answer is (A)
Question 2(iv)
Consider the following code:
result = cursor.fetchmany(2);
print(result)
What will be the result if it is executed after the code given in (iii)?
(A) 1101, Anubhav Singh, BCom, Awaited 1102, Riya Sharma, BSc, Passed
(B) 1102, Riya Sharma, BSc, Passed 1103, Kartikey Rana, BSc, Passed
(C) 1103, Kartikey Rana, BSc, Passed 1104, Archana Kapoor, BBA, Awaited
(D) None of these
Answer:
The given code will display the second and third record from the result set. The fetchmany( ) function retrieves the given number of records from the result set from the current cursor position.
Checking the options
-
(A) 1101, Anubhav Singh, BCom, Awaited
1102, Riya Sharma, BSc, Passed -
(B) 1102, Riya Sharma, BSc, Passed
1103, Kartikey Rana, BSc, Passed
(C) 1103, Kartikey Rana, BSc, Passed
1104, Archana Kapoor, BBA, Awaited - (D) None of these
In the options given above, option B has both the 2nd and 3rd record of table STUDENT.
So, the correct answer is (B)
Question 2(v)
Consider the following code:
cursor=db.cursor()
query = "DELETE FROM student WHERE course
= ‘BCom’ AND result = ‘Awaited’ “
cursor.execute(query)
del_rows= cursor.rowcount
print(del_rows)
What will be the output of the above code?
(A) 1
(B) 2
(C) 3
(D) 4
Answer:
The given code will display the number of records that match the criteria mentioned in the query and is deleted from the table.
Checking the options:
- (A) 1
- (B) 2
- (C) 3
- (D) 4
Since records with Stud 1101 and 1105 match the criteria mentioned in the query, it is deleted from the table,so the output of the code will be 2 .
So, the correct answer is (B)