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 design web page layouts
B. To compile application code
C. To manage network hardware
D. To store and organize data

2 What does DBMS stand for?

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

3 Which company develops Microsoft SQL Server?

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

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

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

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

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

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

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

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

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

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

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

9 Which SQL command changes existing data in a table?

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

10 Which constraint uniquely identifies each row in a table?

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

11 Which constraint prevents a column from containing NULL values?

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

12 Which SQL clause filters rows according to a condition?

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

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

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

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

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

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

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

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

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

17 What is a SQL Server view?

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

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

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

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

User Defined Views Easy
A. CREATE INDEX EmployeeView AS
B. CREATE PROC EmployeeView AS
C. CREATE TABLE EmployeeView AS
D. CREATE VIEW 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 temporary copy of a table
D. A rule that validates a column

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. Table normalization
B. Data redundancy
C. Index fragmentation
D. Transaction atomicity

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. IDENTITY
B. DEFAULT
C. COMPUTED
D. UNIQUE

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. Document database
B. Key-value database
C. Relational database
D. Graph database

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

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

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

SQL Server Tables Medium
A. ALTER Orders CREATE Notes nvarchar(200) NULL;
B. ALTER TABLE Orders ADD Notes nvarchar(200) NULL;
C. MODIFY TABLE Orders Notes nvarchar(200) NULL;
D. UPDATE 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. ALTER e SET Salary = Salary * 1.10 FROM Employees e JOIN Departments d ON e.DepartmentID = d.DepartmentID;
B. INSERT 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. FOREIGN KEY
B. DEFAULT
C. CHECK
D. PRIMARY KEY

28 Which query returns departments having more than five employees?

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

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

SQL Operators Medium
A. ManagerID = NULL
B. ManagerID == NULL
C. ManagerID IS NULL
D. ManagerID IN 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. RIGHT JOIN Customers
C. LEFT JOIN Orders
D. INNER JOIN Orders

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. Self-join Employees using two aliases
B. Cross-join Employees without aliases
C. Group Employees by ManagerID
D. Union Employees with itself

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. Duplicate rows for faster updates
D. Store independent copied records

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 columnstore index
B. A filtered nonclustered index
C. A full-text index
D. A unique clustered index

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

User Defined Views Medium
A. CREATE VIEW ActiveProducts AS SELECT ProductID, Name FROM Products WHERE IsActive = 1;
B. CREATE TABLE ActiveProducts AS SELECT ProductID, Name FROM Products WHERE IsActive = 1;
C. SELECT VIEW ActiveProducts AS ProductID, Name FROM Products WHERE IsActive = 1;
D. CREATE ActiveProducts VIEW 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 converts tables into temporary files
C. It centralizes reusable database logic
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. EXEC GetOrders @CustomerID = 25;
B. RUN GetOrders WITH 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. UNIQUE (EndDate >= StartDate)
B. CHECK (EndDate >= StartDate)
C. DEFAULT (EndDate >= StartDate)
D. FOREIGN KEY (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 ANY (SELECT CustomerID FROM Orders) <> c.CustomerID
B. WHERE ALL (SELECT CustomerID FROM Orders) = c.CustomerID
C. WHERE EXISTS (SELECT 1 FROM Orders o WHERE o.CustomerID = c.CustomerID)
D. WHERE c.CustomerID BETWEEN (SELECT CustomerID FROM Orders)

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 RECOMPILE
B. WITH ENCRYPTION
C. WITH CHECK OPTION
D. WITH SCHEMABINDING

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 OUTPUT
C. @OrderID int IDENTITY
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. Boyce-Codd Normal Form
B. First Normal Form only
C. Third Normal Form only
D. Second Normal Form only

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 only within the statement that created it
B. It is visible to the creating procedure and nested procedures
C. It is visible to every session until explicitly dropped
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. Time-series database
B. Document database
C. Relational database
D. Key-value 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. TRUNCATE cannot be rolled back; DELETE can be rolled back
B. DELETE and TRUNCATE both preserve the current identity value
C. DELETE is rollback-capable and resets identity; TRUNCATE normally preserves identity
D. TRUNCATE is rollback-capable and resets identity; DELETE normally preserves identity

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 page number only and scans that page for every matching row
B. It stores a RID for heaps and the clustering key for clustered tables
C. It stores the primary key regardless of the table's physical organization
D. It stores the clustering key for heaps and a RID for clustered tables

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 once using an unspecified matching source row
B. The target row is updated repeatedly in source-table insertion order
C. The statement fails because the join does not preserve target uniqueness
D. The target row receives the arithmetic average of all matching prices

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. -0.01
B. 0.00
C. -100.00
D. NULL

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

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

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

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 NOT EXISTS (SELECT 1 FROM B WHERE B.ID = A.ID)
B. WHERE A.ID <> ALL (SELECT ISNULL(B.ID, A.ID) FROM B)
C. WHERE EXISTS (SELECT 1 FROM B WHERE B.ID <> A.ID)
D. WHERE A.ID != (SELECT DISTINCT B.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. FULL JOIN Orders AS o ON o.CustomerID = c.CustomerID WHERE o.Status = 'Open'
B. INNER JOIN Orders AS o ON o.CustomerID = c.CustomerID AND o.Status = 'Open'
C. LEFT JOIN Orders AS o ON o.CustomerID = c.CustomerID AND o.Status = 'Open'
D. LEFT 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. 9 rows
B. 11 rows
C. 8 rows
D. 10 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. Descending order because the view stores rows in definition order
B. No ordering guarantee unless the outer query has its own ORDER BY
C. Descending order only when the view uses a clustered primary key
D. Stable order until statistics or indexes on the base table change

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 columnstore index
B. A unique clustered index
C. A unique nonclustered index
D. A filtered 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. The view automatically stores a separate physical copy of all selected account rows
B. Referenced objects cannot be incompatibly altered or dropped while the view depends on them
C. The view bypasses permissions defined on the referenced table and its columns
D. Referenced tables can be renamed freely because dependencies are resolved at execution

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

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

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

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

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 SET NOCOUNT ON to the procedure
B. Add OPTION (RECOMPILE) to the affected statement
C. Add DISTINCT to the affected statement
D. Add WITH SCHEMABINDING 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. @@IDENTITY
B. IDENT_SEED('Orders')
C. SCOPE_IDENTITY()
D. IDENT_CURRENT('TriggerTable')

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