sql banner

SQL Multiple Choice Questions (MCQs) and Answers

Master SQL with Practice MCQs. Explore our curated collection of Multiple Choice Questions. Ideal for placement and interview preparation, our questions range from basic to advanced, ensuring comprehensive coverage of SQL. Begin your placement preparation journey now!

Q181

Q181 What is the primary purpose of the GRANT command in SQL?

A

To create a new table

B

To delete data from a table

C

To give users access privileges

D

To update table data

Q182

Q182 What does the REVOKE command do in SQL?

A

Adds new user accounts

B

Removes specific access privileges from users

C

Deletes tables

D

Inserts data

Q183

Q183 Which part of this statement is incorrect? "GRANT SELECT ON Employees TO user123;"

A

Change 'GRANT' to 'GIVE'

B

Replace 'SELECT ON' with 'SELECT FROM'

C

Change 'user123' to 'User:123'

D

No error

Q184

Q184 Identify the error in
"REVOKE INSERT, UPDATE ON Database FROM user123;"

A

REVOKE

B

INSERT, UPDATE

C

ON Database

D

FROM user123

Q185

Q185 What is the purpose of the COMMIT command in SQL?

A

To start a transaction

B

To save changes made by a transaction

C

To undo changes made by a transaction

D

To revoke user permissions

Q186

Q186 What does the ROLLBACK command do in a transaction?

A

Starts a new transaction

B

Saves the transaction changes

C

Restores the database to the state before the transaction started

D

Grants user permissions

Q187

Q187 How does a transaction in SQL ensure data consistency?

A

By locking the entire database

B

By allowing only one transaction at a time

C

By maintaining a log of all operations

D

By saving changes at regular intervals

Q188

Q188 In the statement "BEGIN TRANSACTION; UPDATE Employees SET Age = Age + 1; COMMIT;", what needs correction?

A

Remove 'BEGIN TRANSACTION'

B

Replace 'COMMIT' with 'END TRANSACTION'

C

Change 'SET Age = Age + 1' to 'SET Age = Age - 1'

D

No error

Q189

Q189 Identify the issue in "ROLLBACK TRANSACTION TO Savepoint1;"

A

Change 'ROLLBACK' to 'REVERT'

B

Remove 'TO'

C

Replace 'Savepoint1' with 'SAVEPOINT1'

D

No error

Q190

Q190 Correct the error in "COMMIT WORK;"

A

Change 'COMMIT' to 'FINISH'

B

Replace 'WORK' with 'TRANSACTION'

C

Add 'TRANSACTION' after 'COMMIT'

D

No error

Q191

Q191 What is the primary role of a primary key in a database table?

A

To sort data

B

To identify unique records

C

To establish relationships with other tables

D

To check data integrity

Q192

Q192 Which constraint ensures that a column cannot have a NULL value?

A

PRIMARY KEY

B

FOREIGN KEY

C

UNIQUE

D

NOT NULL

Q193

Q193 What does the UNIQUE constraint in SQL do?

A

Prevents duplicate values in a column

B

Links two tables together

C

Automatically updates a column

D

Creates a new table

Q194

Q194 What is the purpose of the FOREIGN KEY constraint?

A

To create a new table

B

To ensure unique values in a column

C

To establish a link between two tables

D

To validate data format

Q195

Q195 Which constraint is used to define a condition that each row must satisfy in a SQL table?

A

DEFAULT

B

CHECK

C

PRIMARY KEY

D

UNIQUE

Q196

Q196 How does the DEFAULT constraint function in SQL?

A

It provides a default value for a column when no value is specified

B

It sets default permissions for users

C

It creates default tables

D

It sets default sorting for data

Q197

Q197 Identify the error in
"CREATE TABLE Orders (OrderID int PRIMARY KEY, ProductID int FOREIGN);"

A

CREATE TABLE

B

PRIMARY KEY

C

FOREIGN

D

No error

Q198

Q198 What needs to be corrected in "ALTER TABLE Employees ADD UNIQUE (EmployeeID, Name);"?

A

Change 'ADD' to 'CREATE'

B

Remove 'UNIQUE'

C

Replace '(EmployeeID, Name)' with 'EmployeeID, Name'

D

No error

Q199

Q199 Correct the syntax error in
"CREATE TABLE Students (ID int NOT);"

A

CREATE TABLE

B

Students

C

ID int

D

NOT

Q200

Q200 In the statement "CREATE TABLE Employees (ID int, Salary decimal DEFAULT 10000);", identify the error.

A

Change 'int' to 'integer'

B

Remove 'DEFAULT 10000'

C

Replace 'decimal' with 'number'

D

No error

Q201

Q201 Identify the issue in
"CREATE TABLE Orders (OrderID int, CustomerID int REFERENCES Customers);"

A

CREATE TABLE

B

OrderID int

C

CustomerID int

D

REFERENCES Customers

Q202

Q202 What is missing in "ALTER TABLE Employees ADD CHECK (Age >= 18);"?

A

Add 'CONSTRAINT'

B

Change 'Age >= 18' to 'Age > 18'

C

Include column name before 'CHECK'

D

No error

Q203

Q203 Correct the error in
"CREATE TABLE Products (ProductID int, Price decimal CHECK Price > 0);"

A

CREATE TABLE

B

Price decimal

C

CHECK constraint usage

D

ProductID int

Q204

Q204 Which arithmetic operator is used for division in SQL?

A

"-"

B

"*"

C

"/"

D

"+"

Q205

Q205 In SQL, what does the logical operator AND do when used in a WHERE clause?

A

Selects a record if either condition is true

B

Selects a record if both conditions are true

C

Negates a condition

D

None of the above

Q206

Q206 What does the comparison operator '<>' do in SQL?

A

Checks for equality

B

Checks for inequality

C

Checks if less than

D

Checks if greater than

Q207

Q207 Which bitwise operator performs a logical AND operation on two expressions?

A

& (AND)

B

| (OR)

C

^ (XOR)

D

~ (NOT)

Q208

Q208 In SQL, how does the compound operator '+=' function?

A

Adds two values

B

Adds a value to a column's existing value

C

Subtracts one value from another

D

Concatenates strings

Q209

Q209 What needs correction in "SELECT * FROM Employees WHERE Salary = 5000 AND Department = 'HR';"?

A

Replace '*' with 'Name, Salary'

B

Change '=' to '!=' in 'Salary = 5000'

C

Replace 'AND' with 'OR'

D

No error

Q210

Q210 Identify the error in
"SELECT * FROM Orders WHERE OrderDate >= '2023-01-01' OR >= '2023-06-01';"

A

OR operator

B

>= '2023-06-01'

C

No error

D

The date format

ad vertical
ad