SQL Questions and Answers – SQL Create Table

This set of SQL Multiple Choice Questions & Answers (MCQs) focuses on “SQL Create Table”.

1. Which of the following command is used to create a table in SQL?
a) CREATE
b) MAKE
c) DEVELOP
d) INSERT
View Answer

Answer: a
Explanation: The CREATE command is used to create a table in SQL. The same command can be used to create a database containing the table. The INSERT command is used to insert data inside the tables.

2. In SQL, the CREATE command can be put under which of the following category?
a) DDL (Data Definition Language)
b) DML (Data Manipulation Language)
c) DCL (Data Control Language)
d) TCL (Transaction Control Language)
View Answer

Answer: a
Explanation: In SQL, the CREATE command comes under the category of DDL (Data Definition Language) which is used to define the structure of the table. DML (Data Manipulation Language) is used to manipulate the data inside the table. DCL (Data Control Language) is used by the database administrator to configure security access to relational databases. TCL (Transaction Control Language) is used to commit or rollback the changes made by DML commands.

3. Consider the following syntax and tell whether it is the correct way to create a table in SQL or not.

advertisement
advertisement
CREATE TABLE TABLE_NAME
column1 datatype CONSTRAINT
column2 datatype CONSTRAINT
column3 datatype CONSTRAINT
.
.
.
columnn datatype CONSTRAINT

a) True
b) False
View Answer

Answer: b
Explanation: The syntax for creating a table in SQL always contains an opening bracket before the first column name and a closing bracket and a semicolon at the end of the statement. For example –

CREATE TABLE TABLE_NAME
(column1 datatype CONSTRAINT
column2 datatype CONSTRAINT
column3 datatype CONSTRAINT
.
.
.
columnn datatype CONSTRAINT);

4. It is necessary to specify a constraint for each column.
a) True
b) False
View Answer

Answer: b
Explanation: It is not necessary to specify a constraint for each column. Constraints are used to add some conditions to a column that restricts the column to remain true while inserting or updating or deleting data in that column.
advertisement

5. Which of the following constraint are not present in SQL?
a) UNIQUE
b) NOT NULL
c) PRIMARY KEY
d) CANDIDATE KEY
View Answer

Answer: d
Explanation: CANDIDATE KEY is not present as a constraint in SQL. A Candidate key is the set of columns that can become the Primary Key. The column having the UNIQUE constraint cannot have any duplicate value. The column having the NOT NULL constraint cannot have any null value. The PRIMARY KEY constraint is a combination of UNIQUE and NOT NULL.

6. Which of the following is not a valid datatype in SQL?
a) INT
b) NUMBER
c) VARCHAR
d) DATE
View Answer

Answer: b
Explanation: NUMBER is not a valid datatype in SQL. INT, VARCHAR and DATE are used in SQL to receive an integer, string and date from the user respectively.
advertisement

7. In SQL, a column having the UNIQUE constraint can have two null values.
a) True
b) False
View Answer

Answer: a
Explanation: The UNIQUE constraint is used in a column to restrain it from having similar values. Since, in SQL null means void, it can point towards anything and hence no two null values can be similar.

8. According to the following SQL statement, which of the column is specified as the primary key?

CREATE TABLE STUDENTS 
(ID INT PRIMARY KEY,  
NAME VARCHAR (15) NOT NULL,  
AGE INTNOT NULL,  
ADDRESS CHAR (25));

a) ID
b) NAME
c) AGE
d) ADDRESS
View Answer

Answer: a
Explanation: ID is the column that is specified as the primary key in the given statement. PRIMARY KEY is used to uniquely identify each record in the table.

9. How many columns will be created when the following SQL statement will get executed?

CREATE TABLE Employee  
(Eid INT,  
FName VARCHAR (50),  
LName VARCHAR (50),  
Email VARCHAR (50),  
Address VARCHAR (50),  
City VARCHAR (50));

a) 4
b) 5
c) 6
d) 3
View Answer

Answer: c
Explanation: The given SQL statement will produce a table having 6 columns – Eid, FName, LName, Email, Address and City.

10. Which of the following SQL statement is used to create a table by copying only the selected columns from another table?
a)

CREATE TABLE new_tablename AS (
SELECT * FROM old_tablename WHERE condition);

b)

CREATE TABLE new_tablename AS (
SELECT Column1, Column2...Columnn
FROM old_tablename);

c)

CREATE TABLE new_tablename AS (
SELECT Column1, Column2...ColumnN 
FROM old_tablename1, old_tablename2...old_tablenamen);

d)

CREATE TABLE TABLE_NAME
(column1 datatype CONSTRAINT
column2 datatype CONSTRAINT
column3 datatype CONSTRAINT
...
columnn datatype CONSTRAINT);
View Answer
Answer: b
Explanation:

CREATE TABLE new_tablename AS (
SELECT Column1, Column2...Columnn 
FROM old_tablename);

is used to create a table by copying only the selected columns from another table.

CREATE TABLE new_tablename AS (
SELECT * FROM old_tablename WHERE condition);

is used to create a table by copying all the columns from another table.

CREATE TABLE new_tablename AS (
SELECT Column1, Column2...ColumnN 
FROM old_tablename1, old_tablename2...old_tablenamen);

is used to create a table by copying selected columns from multiple tables.

CREATE TABLE TABLE_NAME
(Column1 datatype CONSTRAINT
Column2 datatype CONSTRAINT
Column3 datatype CONSTRAINT
...
Columnn datatype CONSTRAINT);

is the normal way to create a table.

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]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.