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!

Q31

Q31 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

Q32

Q32 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

Q33

Q33 Which part of this statement is incorrect?

"GRANT SELECT ON Employees TO user123;"

A

GRANT

B

SELECT ON

C

Employees

D

All Correct

Q34

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

A

REVOKE

B

INSERT, UPDATE

C

ON Database

D

FROM user123

Q35

Q35 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

Q36

Q36 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

Q37

Q37 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

Q38

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

A

BEGIN TRANSACTION

B

UPDATE Employees

C

SET Age = Age + 1

D

All Correct

Q39

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

A

ROLLBACK TRANSACTION

B

TO

C

Savepoint1

D

No issue

Q40

Q40 Correct the error in
"COMMIT WORK;"

A

COMMIT

B

WORK

C

No error

D

Semicolon

Q41

Q41 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

Q42

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

A

PRIMARY KEY

B

FOREIGN KEY

C

UNIQUE

D

NOT NULL

Q43

Q43 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

Q44

Q44 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

Q45

Q45 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

Q46

Q46 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

Q47

Q47 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

Q48

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

A

ALTER TABLE

B

ADD UNIQUE

C

(EmployeeID, Name)

D

All Correct

Q49

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

A

CREATE TABLE

B

Students

C

ID int

D

NOT

Q50

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

A

CREATE TABLE

B

ID int

C

Salary decimal

D

No Error

Q51

Q51 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

Q52

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

A

ALTER TABLE

B

ADD CHECK

C

(Age >= 18)

D

All Correct

Q53

Q53 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

Q54

Q54 Which arithmetic operator is used for division in SQL?

A

"-"

B

"*"

C

"/"

D

"+"

Q55

Q55 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

Q56

Q56 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

Q57

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

A

& (AND)

B

| (OR)

C

^ (XOR)

D

~ (NOT)

Q58

Q58 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

Q59

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

A

All Correct

B

= in Salary

C

AND

D

= in Department

Q60

Q60 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