0% found this document useful (0 votes)
9 views

? Master SQL DDL with These 50 Interview Questions!

The document consists of a series of questions and answers related to SQL commands and constraints, focusing on Data Definition Language (DDL). Key topics include the use of commands like CREATE, ALTER, DROP, and TRUNCATE, as well as constraints such as PRIMARY KEY, FOREIGN KEY, and UNIQUE. It also covers the implications of various SQL operations and the behavior of different commands in database management.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

? Master SQL DDL with These 50 Interview Questions!

The document consists of a series of questions and answers related to SQL commands and constraints, focusing on Data Definition Language (DDL). Key topics include the use of commands like CREATE, ALTER, DROP, and TRUNCATE, as well as constraints such as PRIMARY KEY, FOREIGN KEY, and UNIQUE. It also covers the implications of various SQL operations and the behavior of different commands in database management.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

1. What does DDL stand for in SQL?

A) Data Derived Language


B) Data Definition Language
C) Data Deployment Language
D) Data Descriptive Language
Answer: B) Data Definition Language
2. Which of the following is NOT a DDL command?
A) CREATE
B) UPDATE
C) ALTER
D) DROP
Answer: B) UPDATE
3. The CREATE command in SQL is used to:
A) Modify existing records
B) Create new database objects
C) Delete a table
D) Insert values into a table
Answer: B) Create new database objects
4. Which SQL command is used to delete a database permanently?
A) REMOVE DATABASE
B) DELETE DATABASE
C) DROP DATABASE
D) ERASE DATABASE
Answer: C) DROP DATABASE
5. What will happen if you try to drop a table that does not exist?
A) An error occurs
B) The query executes successfully
C) The table is renamed
D) A new table is created
Answer: A) An error occurs
6. Which of the following DDL commands is used to change the structure of an existing table?
A) MODIFY
B) UPDATE
C) ALTER
D) RENAME
Answer: C) ALTER
7. The command to rename an existing table is:
A) ALTER TABLE
B) MODIFY TABLE
C) RENAME TABLE
D) CHANGE TABLE
Answer: C) RENAME TABLE
8. Which of the following constraints ensures that a column cannot have NULL values?
A) UNIQUE
B) PRIMARY KEY
C) NOT NULL
D) CHECK
Answer: C) NOT NULL
9. What does the TRUNCATE command do in SQL?
A) Deletes all rows and the table structure
B) Deletes specific rows based on a condition
C) Removes all rows but keeps the table structure
D) Drops the entire database
Answer: C) Removes all rows but keeps the table structure
10. Which of the following statements is true about the DROP command?
A) It can be rolled back
B) It removes only the data, not the structure
C) It removes both data and structure
D) It renames the table
Answer: C) It removes both data and structure
11. The PRIMARY KEY constraint:
A) Allows duplicate values
B) Cannot be applied to multiple columns
C) Ensures uniqueness and NOT NULL
D) Allows NULL values
Answer: C) Ensures uniqueness and NOT NULL
12. The FOREIGN KEY constraint is used to:
A) Ensure that each value is unique
B) Maintain referential integrity
C) Allow NULL values in a table
D) Improve query performance
Answer: B) Maintain referential integrity
13. Which statement correctly creates a new database named sales_db
A) MAKE DATABASE sales_db;
B) CREATE DATABASE sales_db;
C) ADD DATABASE sales_db;
D) NEW DATABASE sales_db;
Answer: B) CREATE DATABASE sales_db;
14. A UNIQUE constraint ensures:
A) All values in a column are different
B) The column cannot have NULL values
C) The column is indexed
D) The column is a foreign key
Answer: A) All values in a column are different
15. Which SQL statement is used to remove an existing column from a table?
A) DELETE COLUMN
B) REMOVE COLUMN
C) ALTER TABLE … DROP COLUMN
D) ERASE COLUMN
Answer: C) ALTER TABLE … DROP COLUMN
16. The CHECK constraint is used to:
A) Ensure data integrity
B) Define relationships between tables
C) Automatically increment values
D) Create indexes
Answer: A) Ensure data integrity
17. Which SQL command is used to modify an existing column’s data type?
A) ALTER TABLE … MODIFY
B) CHANGE TABLE … TYPE
C) UPDATE TABLE … TYPE
D) ALTER COLUMN … CHANGE
Answer: A) ALTER TABLE … MODIFY
18. What will the following SQL statement do?
DROP TABLE employees;
A) Deletes all records from employees
B) Deletes the table and its structure
C) Renames the table
D) Removes only the first row
Answer: B) Deletes the table and its structure
19. Which of the following is a valid SQL constraint?
A) LIMIT
B) DEFAULT
C) INDEX
D) CASE
Answer: B) DEFAULT
20. What happens when you execute the TRUNCATE TABLE statement?
A) It removes all rows but retains the table structure
B) It permanently deletes the table
C) It deletes only a few rows
D) It cannot be rolled back
Answer: A) It removes all rows but retains the table structure
21. Can the ALTER TABLE command be used to rename a table?
A) Yes
B) No
Answer: A) Yes
22. What is the default value of a column if no default is specified?
A) NULL
B) 0
C) Empty String
D) Depends on the data type
Answer: A) NULL
23. The command to remove a foreign key constraint is:
A) ALTER TABLE … DROP CONSTRAINT
B) DELETE FOREIGN KEY
C) REMOVE FOREIGN KEY
D) ALTER TABLE … DELETE CONSTRAINT
Answer: A) ALTER TABLE … DROP CONSTRAINT
24. What is the correct way to add a new column to an existing table?
A) ALTER TABLE table_name ADD column_name data_type;
B) INSERT INTO table_name (column_name);
C) CREATE COLUMN table_name (column_name);
D) MODIFY TABLE table_name ADD COLUMN column_name;
Answer: A) ALTER TABLE table_name ADD column_name data_type;
25. The UNIQUE constraint:
A) Allows duplicate values
B) Ensures that all values in a column are distinct
C) Can be applied to only one column
D) Is the same as the PRIMARY KEY constraint
Answer: B) Ensures that all values in a column are distinct
26. Which DDL command is used to change the data type of a column?
A) MODIFY
B) CHANGE
C) ALTER
D) UPDATE
Answer: C) ALTER
27. Which of the following commands permanently deletes a database?
A) DROP DATABASE
B) DELETE DATABASE
C) REMOVE DATABASE
D) ERASE DATABASE
Answer: A) DROP DATABASE
28. The PRIMARY KEY constraint can be applied to:
A) Only one column
B) Multiple columns
C) Only numeric columns
D) Only string columns
Answer: B) Multiple columns
29. The DEFAULT constraint:
A) Prevents NULL values
B) Assigns a default value when no value is provided
C) Ensures uniqueness
D) Limits the number of records
Answer: B) Assigns a default value when no value is provided
30. What will happen if you try to create a table that already exists?
A) An error occurs
B) A new table is created with a different name
C) The existing table is overwritten
D) The command is ignored
Answer: A) An error occurs
31. Which SQL command is used to rename a column?
A) RENAME COLUMN
B) MODIFY COLUMN
C) ALTER TABLE … RENAME COLUMN
D) CHANGE COLUMN
Answer: C) ALTER TABLE … RENAME COLUMN
32. Can a table have multiple foreign keys?
A) Yes
B) No
Answer: A) Yes
33. Which command is used to delete all records from a table without deleting the table structure?
A) DELETE
B) TRUNCATE
C) DROP
D) CLEAR
Answer: B) TRUNCATE
34. Which of the following cannot be rolled back?
A) DELETE
B) TRUNCATE
C) INSERT
D) UPDATE
Answer: B) TRUNCATE
35. What is the main difference between DELETE and DROP?
A) DELETE removes only data, DROP removes data and structure
B) DELETE removes data permanently, DROP does not
C) DELETE can be used on databases, DROP cannot
D) DROP removes only selected records
Answer: A) DELETE removes only data, DROP removes data and structure
36. The purpose of an INDEX in SQL is to:
A) Speed up query execution
B) Store data
C) Create relationships between tables
D) Delete records
Answer: A) Speed up query execution
37. Which statement correctly adds a PRIMARY KEY to an existing table?
A) ALTER TABLE table_name ADD PRIMARY KEY (column_name);
B) MODIFY TABLE table_name PRIMARY KEY (column_name);
C) CHANGE TABLE table_name ADD PRIMARY KEY (column_name);
D) ALTER TABLE table_name PRIMARY (column_name);
Answer: A) ALTER TABLE table_name ADD PRIMARY KEY (column_name);
38. The CASCADE option in a FOREIGN KEY constraint ensures:
A) Automatic deletion of related records
B) Prevents deletion of referenced records
C) Adds duplicate records
D) Allows NULL values
Answer: A) Automatic deletion of related records
39. Which of the following is NOT a valid SQL constraint?
A) UNIQUE
B) DEFAULT
C) FOREIGN KEY
D) LINK
Answer: D) LINK
40. What does the AUTO_INCREMENT constraint do?
A) Automatically generates unique values for a column
B) Automatically updates foreign keys
C) Deletes duplicate values
D) Assigns default values
Answer: A) Automatically generates unique values for a column
41. The command to remove an existing PRIMARY KEY constraint is:
A) ALTER TABLE … DROP PRIMARY KEY
B) REMOVE PRIMARY KEY
C) DELETE PRIMARY KEY
D) ALTER TABLE … DELETE PRIMARY KEY
Answer: A) ALTER TABLE … DROP PRIMARY KEY
42. The COLLATE option in SQL is used for:
A) Defining character set sorting rules
B) Specifying numeric calculations
C) Creating relationships
D) Indexing a table
Answer: A) Defining character set sorting rules
43. A table in SQL can have:
A) Only one primary key
B) Multiple primary keys
C) No constraints
D) More than one DEFAULT constraint per column
Answer: A) Only one primary key
44. The DROP command in SQL:
A) Removes the table permanently
B) Removes only the data
C) Can be undone using ROLLBACK
D) Deletes only duplicate records
Answer: A) Removes the table permanently
45. What happens if you try to add a column with the same name as an existing column?
A) An error occurs
B) The column is renamed automatically
C) The new column replaces the old one
D) The database crashes
Answer: A) An error occurs
46. What is the default sorting order of an INDEX?
A) Ascending
B) Descending
C) Random
D) None
Answer: A) Ascending
47. Which command would you use to delete an entire database?
A) DELETE DATABASE
B) DROP DATABASE
C) REMOVE DATABASE
D) ERASE DATABASE
Answer: B) DROP DATABASE
48. The UNIQUE constraint allows:
A) Only one NULL value
B) Multiple NULL values
C) No NULL values
D) Only numbers
Answer: B) Multiple NULL values
49. How can you prevent a column from containing NULL values?
A) Using NOT NULL constraint
B) Using UNIQUE constraint
C) Using FOREIGN KEY constraint
D) Using DEFAULT constraint
Answer: A) Using NOT NULL constraint
50. What is the effect of ALTER TABLE … RENAME TO?
A) Renames the table
B) Deletes the table
C) Changes column names
D) Adds a new table
Answer: A) Renames the table

You might also like