Unit 5: SQL Server For Backend Development - Practice Quiz

INT402 — Modern Web Programming Tools And Techniques 60 Questions
0 Correct 0 Wrong 60 Left
0/60

1 What is the main purpose of a database?

Introduction to Databases Easy
A. To compile application code
B. To store and organize data
C. To design web page layouts
D. To manage network hardware

2 What does DBMS stand for?

Introduction to Databases Easy
A. Database Mapping Service
B. Database Management System
C. Data Backup Management Service
D. Digital Business Monitoring System

3 Which company develops Microsoft SQL Server?

Introduction to SQL Server Easy
A. Microsoft
B. IBM
C. Google
D. Oracle

4 Which type of database stores data in tables made of rows and columns?

Types of Databases Easy
A. Relational database
B. Document database
C. Graph database
D. Key-value database

5 Which SQL command is used to create a new database table?

SQL Commands Easy
A. ALTER TABLE
B. CREATE TABLE
C. UPDATE TABLE
D. SELECT TABLE

6 Which SQL command permanently removes an existing table and its data?

SQL Commands Easy
A. DELETE TABLE
B. CLEAR TABLE
C. REMOVE TABLE
D. DROP TABLE

7 What does a row in a SQL Server table usually represent?

SQL Server Tables Easy
A. A query condition
B. A single record
C. A column type
D. A database name

8 Which SQL command adds a new row to a table?

Data Manipulation Commands Easy
A. DELETE
B. INSERT
C. UPDATE
D. SELECT

9 Which SQL command changes existing data in a table?

Data Manipulation Commands Easy
A. CREATE
B. INSERT
C. UPDATE
D. SELECT

10 Which constraint uniquely identifies each row in a table?

Constraints Easy
A. PRIMARY KEY
B. FOREIGN KEY
C. CHECK
D. DEFAULT

11 Which constraint prevents a column from containing NULL values?

Constraints Easy
A. DEFAULT
B. NOT NULL
C. CHECK
D. UNIQUE

12 Which SQL clause filters rows according to a condition?

SQL Clauses Easy
A. ORDER BY
B. FROM
C. GROUP BY
D. WHERE

13 Which SQL clause sorts the rows in a query result?

SQL Clauses Easy
A. ORDER BY
B. WHERE
C. GROUP BY
D. HAVING

14 Which SQL operator checks whether a value is within a specified range?

SQL Operators Easy
A. EXISTS
B. BETWEEN
C. IN
D. LIKE

15 Which SQL operator is commonly used for pattern matching in text?

SQL Operators Easy
A. LIKE
B. AND
C. EXISTS
D. BETWEEN

16 Which join returns only rows with matching values in both joined tables?

SQL Joins Easy
A. FULL JOIN
B. CROSS JOIN
C. LEFT JOIN
D. INNER JOIN

17 What is a SQL Server view?

SQL Server Views Easy
A. A physical copy of an entire database
B. A saved virtual table based on a query
C. A command that deletes table rows
D. A constraint applied to one column

18 Which type of SQL Server view has a unique clustered index and stores its result physically?

Types of Views Easy
A. Indexed view
B. Simple view
C. Partitioned view
D. System view

19 Which statement correctly starts the creation of a user-defined view named EmployeeView?

User Defined Views Easy
A. CREATE VIEW EmployeeView AS
B. CREATE TABLE EmployeeView AS
C. CREATE PROC EmployeeView AS
D. CREATE INDEX EmployeeView AS

20 What is a stored procedure in SQL Server?

Introduction to Stored Procedure Easy
A. A saved group of SQL statements
B. A diagram of table relationships
C. A rule that validates a column
D. A temporary copy of a table

21 A banking application transfers money by deducting an amount from one account and adding it to another. Which database feature ensures that either both operations occur or neither operation occurs?

Introduction to Databases Medium
A. Data redundancy
B. Transaction atomicity
C. Index fragmentation
D. Table normalization

22 A developer wants SQL Server to generate a sequential numeric value automatically whenever a row is inserted. Which column property should be used?

Introduction to SQL Server Medium
A. UNIQUE
B. COMPUTED
C. DEFAULT
D. IDENTITY

23 An application stores customers, orders, and products with well-defined relationships and requires complex joins. Which type of database is most appropriate?

Types of Databases Medium
A. Relational database
B. Document database
C. Graph database
D. Key-value database

24 How are CREATE TABLE, INSERT, and GRANT classified, respectively?

SQL Commands Medium
A. DML, DDL, TCL
B. DDL, DML, DCL
C. TCL, DML, DDL
D. DDL, DCL, DML

25 The Orders table already contains data. Which statement safely adds an optional Notes column?

SQL Server Tables Medium
A. MODIFY TABLE Orders Notes nvarchar(200) NULL;
B. ALTER Orders CREATE Notes nvarchar(200) NULL;
C. UPDATE TABLE Orders ADD Notes nvarchar(200) NULL;
D. ALTER TABLE Orders ADD Notes nvarchar(200) NULL;

26 Which SQL Server statement increases the salary of employees in the Sales department by 10% using a join?

Data Manipulation Commands Medium
A. INSERT e SET Salary = Salary * 1.10 FROM Employees e JOIN Departments d ON e.DepartmentID = d.DepartmentID;
B. ALTER e SET Salary = Salary * 1.10 FROM Employees e JOIN Departments d ON e.DepartmentID = d.DepartmentID;
C. UPDATE e SET Salary = Salary * 1.10 FROM Employees e JOIN Departments d ON e.DepartmentID = d.DepartmentID WHERE d.Name = 'Sales';
D. UPDATE Employees SET Salary = Salary * 1.10 JOIN Departments d WHERE d.Name = 'Sales';

27 Every order must refer to an existing customer. Which constraint should be placed on Orders.CustomerID?

Constraints Medium
A. DEFAULT
B. PRIMARY KEY
C. CHECK
D. FOREIGN KEY

28 Which query returns departments having more than five employees?

SQL Clauses Medium
A. SELECT DepartmentID FROM Employees GROUP BY DepartmentID WHERE COUNT(*) > 5;
B. SELECT DepartmentID FROM Employees GROUP BY DepartmentID HAVING COUNT(*) > 5;
C. SELECT DepartmentID FROM Employees HAVING COUNT(*) > 5 ORDER BY DepartmentID;
D. SELECT DepartmentID FROM Employees WHERE COUNT(*) > 5 GROUP BY DepartmentID;

29 Which condition correctly selects employees whose ManagerID has no value?

SQL Operators Medium
A. ManagerID = NULL
B. ManagerID == NULL
C. ManagerID IN NULL
D. ManagerID IS NULL

30 A report must list every customer, including customers who have placed no orders. Which join should begin with Customers?

SQL Joins Medium
A. CROSS JOIN Orders
B. INNER JOIN Orders
C. LEFT JOIN Orders
D. RIGHT JOIN Customers

31 The Employees table contains both EmployeeID and ManagerID, where a manager is also an employee. Which technique retrieves each employee together with the manager's name?

SQL Joins Medium
A. Union Employees with itself
B. Group Employees by ManagerID
C. Self-join Employees using two aliases
D. Cross-join Employees without aliases

32 A view displays only nonconfidential employee columns, and users receive SELECT permission on the view but not the base table. What is the main purpose of this design?

SQL Server Views Medium
A. Replace all table constraints
B. Restrict access to selected data
C. Store independent copied records
D. Duplicate rows for faster updates

33 In SQL Server, what must be created first to materialize and index the result of a schema-bound view?

Types of Views Medium
A. A unique clustered index
B. A columnstore index
C. A filtered nonclustered index
D. A full-text index

34 Which statement creates a user-defined view showing only active products?

User Defined Views Medium
A. CREATE ActiveProducts VIEW SELECT ProductID, Name FROM Products WHERE IsActive = 1;
B. SELECT VIEW ActiveProducts AS ProductID, Name FROM Products WHERE IsActive = 1;
C. CREATE VIEW ActiveProducts AS SELECT ProductID, Name FROM Products WHERE IsActive = 1;
D. CREATE TABLE ActiveProducts AS SELECT ProductID, Name FROM Products WHERE IsActive = 1;

35 Why is a stored procedure often preferred when the same multi-statement database operation is executed by several applications?

Introduction to Stored Procedure Medium
A. It removes the need for permissions
B. It centralizes reusable database logic
C. It converts tables into temporary files
D. It guarantees every query uses an index

36 Given CREATE PROCEDURE GetOrders @CustomerID int AS ..., which statement correctly executes the procedure for customer 25?

User Defined Stored Procedure Medium
A. RUN GetOrders WITH CustomerID = 25;
B. EXEC GetOrders @CustomerID = 25;
C. CALL GetOrders CustomerID AS 25;
D. SELECT GetOrders FROM CustomerID = 25;

37 A table must reject rows where EndDate is earlier than StartDate, while allowing equal dates. Which constraint expression is appropriate?

Constraints Medium
A. FOREIGN KEY (EndDate >= StartDate)
B. DEFAULT (EndDate >= StartDate)
C. CHECK (EndDate >= StartDate)
D. UNIQUE (EndDate >= StartDate)

38 A query must return customers who have at least one order. Which condition directly tests whether a related order row exists?

SQL Operators Medium
A. WHERE ALL (SELECT CustomerID FROM Orders) = c.CustomerID
B. WHERE ANY (SELECT CustomerID FROM Orders) <> c.CustomerID
C. WHERE c.CustomerID BETWEEN (SELECT CustomerID FROM Orders)
D. WHERE EXISTS (SELECT 1 FROM Orders o WHERE o.CustomerID = c.CustomerID)

39 A developer renames a column in a base table that is referenced by a view. Which view option helps prevent such schema changes from breaking the view definition?

SQL Server Views Medium
A. WITH SCHEMABINDING
B. WITH CHECK OPTION
C. WITH ENCRYPTION
D. WITH RECOMPILE

40 A stored procedure must return a newly generated order ID through a parameter. How should that parameter be declared?

User Defined Stored Procedure Medium
A. @OrderID int RETURN
B. @OrderID int IDENTITY
C. @OrderID int OUTPUT
D. @OrderID int DEFAULT

41 A relation Enrollment(StudentID, CourseID, InstructorID, InstructorOffice) has the functional dependencies (StudentID, CourseID) -> InstructorID and InstructorID -> InstructorOffice. Assuming (StudentID, CourseID) is the only candidate key, what is the highest normal form satisfied?

Introduction to Databases Hard
A. Second Normal Form only
B. Third Normal Form only
C. First Normal Form only
D. Boyce-Codd Normal Form

42 A stored procedure creates a local temporary table named #Work and then calls a nested stored procedure. Which statement correctly describes the table's scope?

Introduction to SQL Server Hard
A. It is visible to every session until explicitly dropped
B. It is visible to the creating procedure and nested procedures
C. It is visible only within the statement that created it
D. It is invisible to nested procedures but visible to dynamic SQL

43 An application requires multi-row ACID transactions, enforced foreign keys, and frequent joins across highly related entities. Which database type is the most natural primary choice?

Types of Databases Hard
A. Key-value database
B. Document database
C. Relational database
D. Time-series database

44 In SQL Server, both commands are executed inside an explicit transaction against a table with an identity column. Which comparison is correct?

SQL Commands Hard
A. DELETE and TRUNCATE both preserve the current identity value
B. TRUNCATE is rollback-capable and resets identity; DELETE normally preserves identity
C. DELETE is rollback-capable and resets identity; TRUNCATE normally preserves identity
D. TRUNCATE cannot be rolled back; DELETE can be rolled back

45 How does SQL Server normally locate base-table rows from the leaf level of a nonclustered index?

SQL Server Tables Hard
A. It stores a RID for heaps and the clustering key for clustered tables
B. It stores the clustering key for heaps and a RID for clustered tables
C. It stores the primary key regardless of the table's physical organization
D. It stores a page number only and scans that page for every matching row

46 Consider UPDATE p SET Price = s.Price FROM Products AS p JOIN PriceStage AS s ON s.ProductID = p.ProductID;. If PriceStage contains multiple rows for one ProductID, what is the safest conclusion?

Data Manipulation Commands Hard
A. The target row is updated repeatedly in source-table insertion order
B. The target row receives the arithmetic average of all matching prices
C. The statement fails because the join does not preserve target uniqueness
D. The target row is updated once using an unspecified matching source row

47 A nullable column is defined as Price decimal(10,2) CHECK (Price > 0). Which value can still be inserted without violating this constraint?

Constraints Hard
A. NULL
B. -100.00
C. 0.00
D. -0.01

48 A child table has a composite foreign key (RegionID, OfficeID) referencing a composite key in a parent table. What happens when a child row contains (7, NULL)?

Constraints Hard
A. The row is rejected because composite keys cannot contain nulls
B. SQL Server converts the null component to the referenced default value
C. A parent row containing exactly (7, NULL) must already exist
D. The foreign-key check is skipped because part of the key is null

49 Why does SELECT Quantity * UnitPrice AS Total FROM Sales WHERE Total > 100; fail, and what is the standard correction?

SQL Clauses Hard
A. WHERE cannot compare numeric expressions; replace it with a HAVING clause
B. WHERE is processed before the alias exists; use a derived table or repeat the expression
C. SELECT aliases require aggregation; add GROUP BY Quantity, UnitPrice
D. Total is reserved by SQL Server; delimit the alias using square brackets

50 A query uses WHERE A.ID NOT IN (SELECT B.ID FROM B), and the subquery returns at least one NULL. What is the most reliable null-safe anti-join replacement?

SQL Operators Hard
A. WHERE A.ID != (SELECT DISTINCT B.ID FROM B)
B. WHERE EXISTS (SELECT 1 FROM B WHERE B.ID <> A.ID)
C. WHERE NOT EXISTS (SELECT 1 FROM B WHERE B.ID = A.ID)
D. WHERE A.ID <> ALL (SELECT ISNULL(B.ID, A.ID) FROM B)

51 A query must return every customer, together with only that customer's open orders when such orders exist. Which predicate placement preserves customers having no open orders?

SQL Joins Hard
A. LEFT JOIN Orders AS o ON o.CustomerID = c.CustomerID WHERE o.Status = 'Open'
B. LEFT JOIN Orders AS o ON o.CustomerID = c.CustomerID AND o.Status = 'Open'
C. INNER JOIN Orders AS o ON o.CustomerID = c.CustomerID AND o.Status = 'Open'
D. FULL JOIN Orders AS o ON o.CustomerID = c.CustomerID WHERE o.Status = 'Open'

52 Table A contains join-key values (1, 1, 2, NULL), while table B contains (1, 1, 1, 3, NULL). How many rows result from A FULL OUTER JOIN B ON A.KeyValue = B.KeyValue?

SQL Joins Hard
A. 8 rows
B. 10 rows
C. 11 rows
D. 9 rows

53 A view is defined using SELECT TOP (100) PERCENT ... ORDER BY CreatedAt DESC. What ordering guarantee does a later SELECT * FROM ViewName receive?

SQL Server Views Hard
A. No ordering guarantee unless the outer query has its own ORDER BY
B. Descending order only when the view uses a clustered primary key
C. Stable order until statistics or indexes on the base table change
D. Descending order because the view stores rows in definition order

54 After creating a schema-bound view that satisfies SQL Server's indexed-view restrictions, which index must be created first to materialize it?

Types of Views Hard
A. A unique nonclustered index
B. A columnstore index
C. A filtered clustered index
D. A unique clustered index

55 A user-defined view is created with WITH SCHEMABINDING and references dbo.Accounts. What is a principal consequence?

User Defined Views Hard
A. Referenced objects cannot be incompatibly altered or dropped while the view depends on them
B. Referenced tables can be renamed freely because dependencies are resolved at execution
C. The view automatically stores a separate physical copy of all selected account rows
D. The view bypasses permissions defined on the referenced table and its columns

56 Which statement correctly distinguishes a stored procedure's integer return status from its output mechanisms?

Introduction to Stored Procedure Hard
A. RETURN and output parameters both support only one nullable integer value
B. RETURN supplies a complete result set; SELECT supplies only status codes
C. RETURN supplies any SQL type; output parameters are restricted to integers
D. RETURN supplies one integer status; output parameters and result sets return data

57 Inside a procedure's CATCH block, XACT_STATE() returns -1. What transaction action is valid?

User Defined Stored Procedure Hard
A. Roll back the transaction and then propagate or handle the error
B. Continue issuing writes before committing the transaction normally
C. Create a savepoint and commit only the operations before it
D. Commit the transaction and then reset the session error state

58 A procedure's query performs well for common parameter values but poorly for rare values because its cached plan was compiled using an unrepresentative first parameter. Which targeted mitigation recompiles only that statement for each execution?

User Defined Stored Procedure Hard
A. Add OPTION (RECOMPILE) to the affected statement
B. Add WITH SCHEMABINDING to the procedure
C. Add DISTINCT to the affected statement
D. Add SET NOCOUNT ON to the procedure

59 An INSERT into Orders fires a trigger that inserts into another identity table. Which expression returns the identity generated for Orders rather than the trigger's identity?

Data Manipulation Commands Hard
A. IDENT_CURRENT('TriggerTable')
B. @@IDENTITY
C. SCOPE_IDENTITY()
D. IDENT_SEED('Orders')

60 A grouped query must retain departments having at least three rows in total and at least two rows whose Amount is non-null. Which HAVING clause is correct?

SQL Clauses Hard
A. HAVING COUNT(*) >= 3 AND COUNT(ISNULL(Amount, 0)) = 2
B. HAVING COUNT(Amount) >= 3 AND COUNT(*) >= 2
C. HAVING COUNT(*) >= 3 AND COUNT(Amount) >= 2
D. HAVING SUM(Amount) >= 3 AND COUNT(Amount) >= 2