This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Auto Increment”.
1. Which of the following is used to generate a unique number whenever a new row is entered in a table in SQL?
a) UNIQUE
b) PRIMARY KEY
c) AUTO INCREMENT
d) INDEX
View Answer
Explanation: In SQL, the AUTO INCREMENT field is used to generate a unique number whenever a new row is added in a table. Most probably the primary key column of a table should be the one where the auto increment field should be applied.
2. In SQL, which of the following statement can be used to apply the AUTO INCREMENT field on a column?
a)
CREATE TABLE TABLE_NAME AUTO_INCREMENT ( column1 datatype CONSTRAINT, column2 datatype CONSTRAINT, ... columnn datatype CONSTRAINT);
b)
CREATE TABLE TABLE_NAME ( column1 datatype CONSTRAINT AUTOINCREMENT, column2 datatype CONSTRAINT, ... columnn datatype CONSTRAINT);
c)
CREATE TABLE TABLE_NAME ( column1 datatype CONSTRAINT, column2 datatype CONSTRAINT, ... columnn datatype CONSTRAINT, AUTO_INCREMENT (column_name));
d)
CREATE TABLE TABLE_NAME ( column1 datatype CONSTRAINT AUTO_INCREMENT, column2 datatype CONSTRAINT, …. columnn datatype CONSTRAINT);
Explanation: The statement that can be used to apply the AUTO INCREMENT field on a column is –
CREATE TABLE TABLE_NAME ( column1 datatype CONSTRAINT AUTO_INCREMENT, column2 datatype CONSTRAINT, ... columnn datatype CONSTRAINT);
The AUTO_INCREMENT keyword is used while using the CREATE command after the column name on which it has to applied.
3. What is the default value by which a record will be increased when the AUTO INCREMENT field is applied on it?
a) 1
b) Specified by the user
c) 10
d) 0
View Answer
Explanation: By default, the starting value for AUTO_INCREMENT is 1, and it will increment by 1 for each new record.
4. We can change the default value of the AUTO INCREMENT field by which a record will be increased?
a) True
b) False
View Answer
Explanation: We can change the default value of the AUTO INCREMENT field by which a record is increased. By default, the value is 1 but we can change the value as according to our need.
5. Which of the following statement is used to change the default value of the AUTO INCREMENT field?
a) ALTER table_name AUTO_INCREMENT=100;
b) ALTER TABLE table_name AUTO_INCREMENT=100;
c) CHANGE TABLE table_name AUTO_INCREMENT=100;
d) ALTER TABLE table_name AUTO_INCREMENT (100);
View Answer
Explanation: The statement that can be used to change the default value of the AUTO INCREMENT field is –
ALTER TABLE TABLE_NAME AUTO_INCREMENT=100;
We use the ALTER command and assign the needed value to the AUTO INCREMENT filed through an equals sign.
6. We have to insert a new record into a table, we will have to specify a value for the column on which the AUTO INCREMENT field is applied.
a) True
b) False
View Answer
Explanation: We do not have to enter a value for the column on which the AUTO INCREMENT field is applied when we are entering a new record. This entry for the column will be automatically generated and filled.
7. Which of the following statement is used to apply the AUTO INCREMENT field on a column with a starting value other than 1?
a) column_name datatype constraint AUTOINCREMENT;
b) column_name datatype constraint AUTOINCREMENT = 10,5;
c) column_name datatype constraint AUTOINCREMENT (10,5);
d) column_name datatype constraint (10,5) AUTOINCREMENT;
View Answer
Explanation: The statement that is used to apply the AUTO INCREMENT field on a column with a starting value other than 1 is –
column_name datatype CONSTRAINT AUTOINCREMENT (10,5);
Here, the starting value for the column would be 10 and it would be automatically increased by 5 every time a new record is added to the column. Also, we use the AUTOINCREMENT keyword in SQL Server rather than the AUTO_INCREMENT keyword which is used in MySQL.
Sanfoundry Global Education & Learning Series – SQL.
To practice all areas of SQL, here is complete set of 1000+ Multiple Choice Questions and Answers.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]