Page 355 - Informatics_Practices_Fliipbook_Class12
P. 355
67. How is Primary key different from Candidate key in MySQL? Explain with example.
Ans. Primary Key is a unique and non-null key which identify a record uniquely in table. A table can have only one
primary key. Candidate key is also a unique key to identify a record uniquely in a table but a table can have
multiple candidate keys.
68. Write commands to display:
(i) the position of string "XI" in the string "XII".
(ii) the string "CbSe" in lower case.
Ans. (i) SELECT INSTR("XI","XII");
(ii) SELECT LOWER("CbSe");
69. Give the output of the following MySQL commands:
(i) SELECT LENGTH(RIGHT("GOOD MORNING",4));
(ii) SELECT DAY('2018-04-24');
Ans. (i) 4
(ii) 24
70. Write commands in SQL to:
(i) display seven characters from the end of the string "Grow More Trees".
(ii) display numeric month for the date 2021-10-18.
Ans. (i) SELECT RIGHT("Grow More Trees",7);
(ii) SELECT MONTH("2021-10-18");
71. Write the SQL command that will display the current time and date.
Ans. SELECT NOW();
72. What is the difference between the order by and group by clause when used along with the select statement.
Explain with an example. [CBSE Sample Paper, 2021]
Ans. The order by clause is used to show the contents of a table/relation in a sorted manner with respect to the
column mentioned after the order by clause. The contents of the column can be arranged in ascending or
descending order.
The group by clause is used to group rows in a given column and then apply an aggregate function eg max(),
min() etc on the entire group.
73. Considering the same string "PREOCCUPIED" [CBSE Sample Paper, 2021]
Write SQL commands to display:
(i) the position of the substring 'cup' in the string "Preoccupied".
(ii) the first 4 letters of the string.
Ans. (i) SELECT INSTR 'Preoccupied', ' 'cup'));
(ii) SELECT LEFT 'PREOCCUPIED',4);
74. Find the output of the following SQL queries: [CBSE, 2022]
(i) SELECT SUBSTR("FIT INDIA MOVEMENT",5);
(ii) SELECT INSTR("ARTIFICIAL INTELLIGENCE", "IA");
Ans. (i) INDIA MOVEMENT
(ii) 8
Viva Voce Questions 341

