Which SQL keyword is used to define a unique constraint on a column?
a) UNIQUE b) DISTINCT c) PRIMARY KEY d) NOT NULL
Correct Answer: a) UNIQUE
Explanation: The UNIQUE constraint ensures that all values in a column are distinct, preventing duplicate entries.
Question 42
Which SQL command is used to modify the data type of an existing column in a table?
a) CHANGE COLUMN b) MODIFY COLUMN c) ALTER COLUMN d) UPDATE COLUMN
Correct Answer: c) ALTER COLUMN
Explanation: The ALTER TABLE statement with ALTER COLUMN is used to change the data type of an existing column in SQL.
Question 43
What does the LIKE operator do in a SQL query?
a) Compares two values for equality b) Matches a string against a pattern c) Counts rows in a result set d) Sorts results in ascending order
Correct Answer: b) Matches a string against a pattern
Explanation: The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.
Question 44
Which SQL function can be used to extract a substring from a string?
a) SUBSTRING() b) EXTRACT() c) MID() d) SPLIT()
Correct Answer: a) SUBSTRING()
Explanation: The SUBSTRING() function extracts a portion of a string based on a specified starting position and length.
Question 45
Which SQL command is used to define a relationship between tables?
a) CREATE RELATIONSHIP b) DEFINE RELATION c) FOREIGN KEY d) LINK TABLES
Correct Answer: c) FOREIGN KEY
Explanation: The FOREIGN KEY constraint is used to define a relationship between two tables, ensuring referential integrity.
Question 46
Which SQL function would you use to return the first character of a string?
a) LEFT() b) FIRST() c) SUBSTR() d) CHAR()
Correct Answer: a) LEFT()
Explanation: The LEFT() function returns the first specified number of characters from a string.
Question 47
Which SQL command is used to grant access to a user?
a) GIVE b) GRANT c) ALLOW d) PROVIDE
Correct Answer: b) GRANT
Explanation: The GRANT command assigns specific privileges to a user or role in the database, allowing access to data and operations.
Question 48
What is the primary purpose of an index in a database?
a) To increase redundancy b) To improve query performance c) To enforce data integrity d) To delete records
Correct Answer: b) To improve query performance
Explanation: An index improves the speed of data retrieval operations on a database table, making queries more efficient.
Question 49
Which SQL command is used to remove all rows from a table without removing the table itself?
a) DELETE b) DROP c) TRUNCATE d) CLEAR
Correct Answer: c) TRUNCATE
Explanation: The TRUNCATE command deletes all rows in a table while keeping the table structure intact.
Question 50
What does the SQL function ROUND() do?
a) Converts a value to an integer b) Rounds a numeric value to a specified number of decimal places c) Calculates the square root of a number d) Finds the maximum value in a column
Correct Answer: b) Rounds a numeric value to a specified number of decimal places
Explanation: The ROUND() function is used to round a numeric value to a specified number of decimal places.