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

SQL Bank

Uploaded by

mohamedmegz100
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

SQL Bank

Uploaded by

mohamedmegz100
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 30

Database Ques on Bank

1. What does RDBMS stand for?


a) Random Data Management System
b) Relational Database Management System
c) Regular Database Management System
d) Restricted Database Management System
Answer: b) Relational Database Management System
2. In a relational database, a column is also referred to as a:
a) Record
b) Tuple
c) Field
d) Attribute
Answer: d) Attribute
3. Which of the following is used to uniquely identify a row in a table?
a) Foreign Key
b) Candidate Key
c) Primary Key
d) Index
Answer: c) Primary Key
4. Which SQL command is used to retrieve data from a database?
a) SELECT
b) INSERT
c) UPDATE
d) DELETE
Answer: a) SELECT
5. The command to delete a table and its data permanently is:
a) DELETE
b) TRUNCATE
c) DROP TABLE
d) CLEAR
Answer: c) DROP TABLE
6. Which SQL clause is used to filter records?
a) ORDER BY
b) WHERE
c) GROUP BY
d) HAVING
Answer: b) WHERE
7. A column with a NOT NULL constraint:
a) Cannot have duplicate values
b) Cannot have NULL values
c) Must have a unique constraint
d) Can only store numeric values
Answer: b) Cannot have NULL values
8. The UNIQUE constraint ensures:
a) All columns are indexed
b) No NULL values are present
c) Each value in a column is distinct
d) Columns cannot be updated
Answer: c) Each value in a column is distinct
Chapter 4: Entity Relationship Diagram
9. The SQL command to create a new table is:
a) CREATE DATABASE
b) CREATE TABLE
c) CREATE INDEX
d) CREATE VIEW
Answer: b) CREATE TABLE
10. In an ER diagram, a rectangle represents a:
a) Attribute
b) Relationship
c) Entity
d) Primary Key
Answer: c) Entity
1. What is the foundation of modern database systems like Oracle and
MySQL?
a) File-based Systems
b) RDBMS
c) Flat-file Databases
d) None of the above
Answer: b) RDBMS
2. In an RDBMS, data is stored in:
a) Files
b) Arrays
c) Tables
d) Stacks
Answer: c) Tables
3. Which of the following uniquely identifies a record in a table?
a) Foreign Key
b) Primary Key
c) Unique Key
d) Index
Answer: b) Primary Key
4. A column in a table represents:
a) A tuple
b) An attribute
c) A relationship
d) A file
Answer: b) An attribute
5. Which is NOT a characteristic of a Primary Key?
a) Must be unique
b) Can be NULL
c) Cannot be changed
d) Identifies rows uniquely
Answer: b) Can be NULL
6. Which command is used to create a database?
a) CREATE TABLE
b) CREATE DATABASE
c) CREATE VIEW
d) CREATE SCHEMA
Answer: b) CREATE DATABASE
7. Which SQL clause is used to filter results?
a) SELECT
b) WHERE
c) FROM
d) ORDER BY
Answer: b) WHERE
8. The syntax to delete a database is:
a) DELETE DATABASE db_name;
b) DROP DATABASE db_name;
c) REMOVE DATABASE db_name;
d) ERASE DATABASE db_name;
Answer: b) DROP DATABASE db_name;
9. The default sorting order in SQL is:
a) Descending
b) Ascending
c) Random
d) None
Answer: b) Ascending
10. Which operator is used to check a range of values in SQL?
a) IN
b) BETWEEN
c) LIKE
d) EXISTS
Answer: b) BETWEEN
11. Which data type is best for a column storing a fixed-length string?
a) VARCHAR
b) CHAR
c) TEXT
d) STRING
Answer: b) CHAR
12. Which data type is used for a floating-point number?
a) INT
b) FLOAT
c) DOUBLE
d) DECIMAL
Answer: b) FLOAT
13. To store a date and time, use the data type:
a) DATE
b) TIME
c) DATETIME
d) TIMESTAMP
Answer: c) DATETIME
14. Which type is suitable for storing a large text?
a) VARCHAR
b) CHAR
c) TEXT
d) INT
Answer: c) TEXT
15. The SELECT command retrieves data from:
a) Tables
b) Views
c) Both a and b
d) None of the above
Answer: c) Both a and b
16. Which command is used to update existing records?
a) MODIFY
b) ALTER
c) UPDATE
d) CHANGE
Answer: c) UPDATE
17. To delete only data (not table structure), use:
a) DROP
b) TRUNCATE
c) DELETE
d) REMOVE
Answer: c) DELETE
18. To rename a table temporarily in a query, use:
a) REPLACE
b) ALIAS
c) TEMP RENAME
d) PSEUDO
Answer: b) ALIAS
19. What does the DISTINCT keyword do in SQL?
a) Filters duplicates
b) Sorts data
c) Joins tables
d) None of the above
Answer: a) Filters duplicates

20. Which constraint ensures that no two rows have the same value?
a) UNIQUE
b) NOT NULL
c) DEFAULT
d) CHECK
Answer: a) UNIQUE
21. What does the NOT NULL constraint ensure?
a) No duplicates
b) Column cannot be NULL
c) Default values are assigned
d) Validates conditions
Answer: b) Column cannot be NULL
22. A Foreign Key is used to:
a) Delete a table
b) Reference a Primary Key in another table
c) Create unique values
d) Sort data
Answer: b) Reference a Primary Key in another table
23. Which constraint ensures a default value?
a) UNIQUE
b) DEFAULT
c) NOT NULL
d) PRIMARY KEY
Answer: b) DEFAULT

24. What does the HAVING clause do in SQL?


a) Filters results after grouping
b) Filters duplicate values
c) Specifies grouping criteria
d) Limits the number of rows
Answer: a) Filters results after grouping
25. The JOIN operation combines:
a) Tables
b) Rows
c) Columns
d) Views
Answer: a) Tables
26. An entity in an ER diagram is represented by a:
a) Rectangle
b) Oval
c) Diamond
d) Triangle
Answer: a) Rectangle
27. A relationship in an ER diagram is depicted as a:
a) Rectangle
b) Oval
c) Diamond
d) Line
Answer: c) Diamond
28. Attributes in an ER diagram are represented by:
a) Rectangles
b) Diamonds
c) Lines
d) Ovals
Answer: d) Ovals
29. The primary key is often underlined in:
a) SQL syntax
b) ER diagrams
c) Database tables
d) None of the above
Answer: b) ER diagrams
36. Which operator is used for pattern matching?
a) LIKE
b) IN
c) BETWEEN
d) EXISTS
Answer: a) LIKE
37. Which of these is a logical operator in SQL?
a) ALL
b) AND
c) BETWEEN
d) NULL
Answer: b) AND
38. The NOT operator is used to:
a) Reverse a condition
b) Select NULL values
c) Join tables
d) Create indexes
Answer: a) Reverse a condition
39. The modulus operator (%) is used to:
a) Find the remainder of a division
b) Multiply two numbers
c) Compare values
d) None of the above
Answer: a) Find the remainder of a division
40. Which of the following is NOT a comparison operator?
a) =
b) <>
c) <=
d) IN
Answer: d) IN

41. The GROUP BY clause is used to:


a) Filter rows
b) Sort data
c) Group rows with the same values
d) None of the above
Answer: c) Group rows with the same values
42. Which aggregate function is used to count non-NULL values?
a) SUM()
b) AVG()
c) COUNT()
d) MAX()
Answer: c) COUNT()
43. The HAVING clause is used in combination with:
a) WHERE
b) GROUP BY
c) SELECT
d) INSERT
Answer: b) GROUP BY
44. Which function finds the largest value in a set?
a) MIN()
b) AVG()
c) MAX()
d) SUM()
Answer: c) MAX()
45. The COUNT function returns:
a) Total number of rows
b) Sum of values
c) Average of values
d) None of the above
Answer: a) Total number of rows

46. The CHECK constraint is used to:


a) Validate data before insertion
b) Define default values
c) Prevent NULL values
d) Link tables
Answer: a) Validate data before insertion
47. The FOREIGN KEY constraint ensures:
a) Uniqueness of rows
b) Referential integrity
c) Default values are applied
d) Data types match
Answer: b) Referential integrity
48. A composite key is made up of:
a) Multiple foreign keys
b) Multiple attributes
c) A unique constraint
d) None of the above
Answer: b) Multiple attributes
49. Which statement drops a UNIQUE constraint?
a) DROP UNIQUE
b) ALTER TABLE table_name DROP CONSTRAINT constraint_name;
c) DELETE UNIQUE
d) None of the above
Answer: b) ALTER TABLE table_name DROP CONSTRAINT
constraint_name;
50. The DEFAULT constraint applies a value when:
a) A column is NULL
b) No value is provided during insertion
c) A column violates the NOT NULL constraint
d) Both a and b
Answer: b) No value is provided during insertion

51. Which of the following SQL statements is used to retrieve all rows from
a table?
a) SELECT * FROM table_name
b) SELECT table_name
c) FETCH table_name
d) GET table_name
Answer: a) SELECT * FROM table_name
52. To rename a table, which command is used?
a) RENAME TABLE old_name TO new_name
b) ALTER TABLE old_name RENAME TO new_name
c) CHANGE TABLE old_name TO new_name
d) None of the above
Answer: b) ALTER TABLE old_name RENAME TO new_name
53. The DELETE statement without a WHERE clause:
a) Deletes a single row
b) Deletes all rows from the table
c) Displays an error
d) Deletes the table itself
Answer: b) Deletes all rows from the table
54. Which clause is used to sort the result of a query?
a) SORT BY
b) ORDER BY
c) GROUP BY
d) HAVING
Answer: b) ORDER BY
55. To limit the number of rows returned by a query, use:
a) LIMIT
b) WHERE
c) ROWS
d) DISTINCT
Answer: a) LIMIT

56. Which command is used to add a new row to a table?


a) INSERT
b) UPDATE
c) SELECT
d) ALTER
Answer: a) INSERT
57. To modify existing data in a table, use:
a) INSERT
b) UPDATE
c) ALTER
d) MODIFY
Answer: b) UPDATE
58. Which statement removes data but retains the table structure?
a) TRUNCATE
b) DELETE
c) DROP
d) REMOVE
Answer: a) TRUNCATE
59. The MERGE command in SQL is used for:
a) Joining two tables
b) Inserting and updating data in one command
c) Deleting data
d) Creating indexes
Answer: b) Inserting and updating data in one command
60. Which statement removes a table from the database?
a) DELETE TABLE
b) DROP TABLE
c) REMOVE TABLE
d) CLEAR TABLE
Answer: b) DROP TABLE
61. What does the ALTER TABLE command do?
a) Inserts a new row
b) Modifies the table structure
c) Deletes the table
d) Renames the table
Answer: b) Modifies the table structure
62. The CREATE TABLE command is used to:
a) Add a column to a table
b) Create a new table
c) Create a new row
d) Delete a table
Answer: b) Create a new table
63. Which clause is used to specify constraints during table creation?
a) WHERE
b) CHECK
c) CONSTRAINT
d) None of the above
Answer: c) CONSTRAINT
64. To create a new database, use:
a) CREATE DATABASE database_name;
b) ADD DATABASE database_name;
c) MAKE DATABASE database_name;
d) SET DATABASE database_name;
Answer: a) CREATE DATABASE database_name;
65. The primary key constraint ensures that:
a) All values are unique and not NULL
b) Values can be NULL
c) All values are numeric
d) Values are updated automatically
Answer: a) All values are unique and not NULL
66. An index improves the performance of:
a) Insert operations
b) Query retrieval speed
c) Deleting rows
d) Creating tables
Answer: b) Query retrieval speed
67. The command to create an index is:
a) CREATE INDEX index_name ON table_name(column_name);
b) ADD INDEX index_name ON table_name(column_name);
c) INDEX column_name ON table_name;
d) None of the above
Answer: a) CREATE INDEX index_name ON table_name(column_name);
68. Which index is automatically created with a primary key?
a) Clustered index
b) Non-clustered index
c) Composite index
d) None of the above
Answer: a) Clustered index
69. The DROP INDEX command:
a) Deletes rows in the index
b) Removes the index from the table
c) Deletes the table
d) Deletes constraints
Answer: b) Removes the index from the table
70. A composite index is created using:
a) A single column
b) Multiple columns
c) Constraints
d) Foreign keys
Answer: b) Multiple columns

71. A view in SQL is:


a) A physical table
b) A virtual table
c) A copy of another table
d) None of the above
Answer: b) A virtual table
72. The command to create a view is:
a) CREATE TABLE view_name
b) CREATE VIEW view_name AS SELECT...
c) CREATE INDEX view_name
d) CREATE SCHEMA view_name
Answer: b) CREATE VIEW view_name AS SELECT...
73. Which statement updates a view?
a) ALTER VIEW
b) UPDATE VIEW
c) MODIFY VIEW
d) None of the above
Answer: a) ALTER VIEW
74. The DROP VIEW command is used to:
a) Delete rows from a view
b) Delete the view
c) Modify the view structure
d) Create a view
Answer: b) Delete the view
75. Views are used for:
a) Security purposes
b) Simplifying complex queries
c) Presenting data in a specific format
d) All of the above
Answer: d) All of the above

76. What is the purpose of the ALTER TABLE command?


a) Modify the table structure
b) Insert new rows
c) Delete rows
d) None of the above
Answer: a) Modify the table structure
77. To add a new column to a table, which syntax is correct?
a) ALTER TABLE table_name ADD COLUMN column_name datatype;
b) ADD COLUMN table_name column_name datatype;
c) MODIFY TABLE table_name ADD COLUMN column_name datatype;
d) None of the above
Answer: a) ALTER TABLE table_name ADD COLUMN column_name
datatype;
78. Which statement removes a column from a table?
a) ALTER TABLE table_name DROP COLUMN column_name;
b) REMOVE COLUMN column_name FROM table_name;
c) DELETE COLUMN column_name FROM table_name;
d) None of the above
Answer: a) ALTER TABLE table_name DROP COLUMN column_name;
79. What does the ALTER TABLE MODIFY statement do?
a) Deletes a column
b) Changes the data type of a column
c) Adds a new table
d) Creates a new database
Answer: b) Changes the data type of a column
80. How do you rename a table?
a) ALTER TABLE old_name RENAME TO new_name;
b) ALTER TABLE old_name CHANGE NAME new_name;
c) MODIFY TABLE old_name TO new_name;
d) None of the above
Answer: a) ALTER TABLE old_name RENAME TO new_name;
81. To set a NOT NULL constraint using ALTER, use:
a) ALTER TABLE table_name MODIFY column_name datatype NOT
NULL;
b) ALTER TABLE table_name ADD CONSTRAINT NOT NULL;
c) ALTER TABLE table_name DROP NULL;
d) None of the above
Answer: a) ALTER TABLE table_name MODIFY column_name datatype
NOT NULL;
82. To add a UNIQUE constraint to an existing column, use:
a) ALTER TABLE table_name ADD CONSTRAINT
UNIQUE(column_name);
b) ALTER TABLE table_name MODIFY column_name UNIQUE;
c) ALTER TABLE table_name DROP UNIQUE(column_name);
d) None of the above
Answer: a) ALTER TABLE table_name ADD CONSTRAINT
UNIQUE(column_name);
83. Which command removes all constraints on a column?
a) ALTER TABLE DROP CONSTRAINT constraint_name;
b) DROP TABLE table_name;
c) REMOVE CONSTRAINT table_name;
d) None of the above
Answer: a) ALTER TABLE DROP CONSTRAINT constraint_name;
84. ALTER TABLE can be used to:
a) Add columns
b) Drop constraints
c) Modify column types
d) All of the above
Answer: d) All of the above
85. How can you drop the primary key of a table?
a) ALTER TABLE table_name DROP PRIMARY KEY;
b) REMOVE PRIMARY KEY FROM table_name;
c) DELETE PRIMARY KEY ON table_name;
d) None of the above
Answer: a) ALTER TABLE table_name DROP PRIMARY KEY;

86. What is the purpose of the NOT NULL constraint?


a) Ensures a column cannot have NULL values
b) Ensures column values are unique
c) Sets a default value
d) Ensures foreign key relationships
Answer: a) Ensures a column cannot have NULL values
87. Which constraint uniquely identifies a row in a table?
a) PRIMARY KEY
b) FOREIGN KEY
c) UNIQUE
d) CHECK
Answer: a) PRIMARY KEY
88. The FOREIGN KEY constraint is used to:
a) Enforce referential integrity
b) Ensure unique values
c) Allow NULL values
d) Set default values
Answer: a) Enforce referential integrity
89. Which constraint enforces a specific condition on a column's values?
a) CHECK
b) UNIQUE
c) NOT NULL
d) DEFAULT
Answer: a) CHECK
90. A UNIQUE constraint:
a) Allows duplicate values
b) Ensures all values are distinct
c) Can only be applied to numeric data
d) None of the above
Answer: b) Ensures all values are distinct
91. What happens if you try to insert a NULL value into a column with a
NOT NULL constraint?
a) The database ignores the constraint
b) An error occurs
c) The value is replaced with 0
d) None of the above
Answer: b) An error occurs
92. The DEFAULT constraint:
a) Provides a default value when no value is specified
b) Ensures values are unique
c) Prevents NULL values
d) None of the above
Answer: a) Provides a default value when no value is specified
93. Which constraint prevents duplicate values in a column but allows
NULLs?
a) PRIMARY KEY
b) UNIQUE
c) FOREIGN KEY
d) NOT NULL
Answer: b) UNIQUE
94. What is the difference between PRIMARY KEY and UNIQUE?
a) PRIMARY KEY allows NULLs, UNIQUE does not
b) PRIMARY KEY enforces a single unique row identifier, UNIQUE does
not
c) UNIQUE is faster than PRIMARY KEY
d) None of the above
Answer: b) PRIMARY KEY enforces a single unique row identifier,
UNIQUE does not
95. To enforce a relationship between two tables, use:
a) PRIMARY KEY
b) FOREIGN KEY
c) UNIQUE
d) CHECK
Answer: b) FOREIGN KEY

96. The GROUP BY clause is used to:


a) Combine rows with the same values into groups
b) Filter rows
c) Sort rows
d) None of the above
Answer: a) Combine rows with the same values into groups
97. Which clause must be used with GROUP BY to filter aggregated data?
a) WHERE
b) HAVING
c) ORDER BY
d) SELECT
Answer: b) HAVING
98. The GROUP BY clause is typically used with:
a) Aggregation functions
b) Subqueries
c) Joins
d) None of the above
Answer: a) Aggregation functions
99. What does this query do: SELECT city, COUNT(*) FROM employees
GROUP BY city;?
a) Lists all cities with the number of employees in each
b) Filters cities with employees
c) Sorts employees by city
d) None of the above
Answer: a) Lists all cities with the number of employees in each
100. Which query will group employees by department and calculate
the total salary for each?
a) SELECT department, SUM(salary) FROM employees GROUP BY
department;
b) SELECT department, salary FROM employees GROUP BY salary;
c) SELECT department FROM employees ORDER BY salary;
d) None of the above
Answer: a) SELECT department, SUM(salary) FROM employees GROUP
BY department;
101. The ORDER BY clause is used to:
a) Sort rows in ascending or descending order
b) Filter rows
c) Aggregate data
d) None of the above
Answer: a) Sort rows in ascending or descending order
102. The default sorting order in SQL is:
a) Ascending
b) Descending
c) Random
d) None of the above
Answer: a) Ascending
103. To sort in descending order, use:
a) DESC
b) ASC
c) SORT BY
d) None of the above
Answer: a) DESC
104. Which query sorts employees by their salary in descending order?
a) SELECT * FROM employees ORDER BY salary DESC;
b) SELECT * FROM employees SORT BY salary DESC;
c) SELECT * FROM employees ORDER salary;
d) None of the above
Answer: a) SELECT * FROM employees ORDER BY salary DESC;
105. To sort by multiple columns, use:
a) ORDER BY column1, column2
b) SORT BY column1 AND column2
c) GROUP BY column1, column2
d) None of the above
Answer: a) ORDER BY column1, column2
106. To sort employees by department in ascending order and by salary in
descending order:
a) SELECT * FROM employees ORDER BY department ASC, salary
DESC;
b) SELECT * FROM employees SORT BY department AND salary DESC;
c) SELECT * FROM employees GROUP BY department, salary DESC;
d) None of the above
Answer: a) SELECT * FROM employees ORDER BY department ASC,
salary DESC;
107. Which SQL statement is used to retrieve data from a table?
a) SELECT
b) INSERT
c) UPDATE
d) DELETE
Answer: a) SELECT
108. Which statement is used to insert new rows into a table?
a) ADD
b) INSERT
c) UPDATE
d) MERGE
Answer: b) INSERT
109. To modify existing records in a table, which SQL statement is
used?
a) ALTER
b) MODIFY
c) UPDATE
d) SELECT
Answer: c) UPDATE
110. Which SQL statement is used to delete specific rows from a
table?
a) TRUNCATE
b) REMOVE
c) DELETE
d) DROP
Answer: c) DELETE
111. What does the TRUNCATE statement do?
a) Deletes specific rows from a table
b) Deletes all rows from a table and resets its structure
c) Removes the table from the database
d) Updates rows in a table
Answer: b) Deletes all rows from a table and resets its structure
112. The DROP TABLE statement is used to:
a) Delete all rows from a table
b) Delete a table and its structure permanently
c) Remove duplicate rows from a table
d) Reset a table
Answer: b) Delete a table and its structure permanently
113. Which SQL statement creates a new table?
a) CREATE
b) CREATE TABLE
c) INSERT TABLE
d) ADD TABLE
Answer: b) CREATE TABLE
114. Which statement removes duplicates from the result set?
a) DISTINCT
b) UNIQUE
c) REMOVE DUPLICATES
d) NONE
Answer: a) DISTINCT
115. What does the ORDER BY clause do in SQL?
a) Filters data
b) Groups rows
c) Sorts rows in ascending or descending order
d) Limits rows
Answer: c) Sorts rows in ascending or descending order
116. Which SQL clause filters rows based on a condition?
a) SELECT
b) WHERE
c) GROUP BY
d) HAVING
Answer: b) WHERE
117. The HAVING clause is used to filter rows:
a) Before grouping
b) After grouping
c) During insertion
d) None of the above
Answer: b) After grouping
118. Which SQL clause is used to group rows that have the same
values?
a) ORDER BY
b) GROUP BY
c) FILTER BY
d) DISTINCT
Answer: b) GROUP BY

You might also like