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

2 What does DBMS stand for?

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

3 Which company develops Microsoft SQL Server?

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

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. Key-value database
D. Graph database

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

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

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

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

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

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

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

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

9 Which SQL command changes existing data in a table?

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

10 Which constraint uniquely identifies each row in a table?

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

11 Which constraint prevents a column from containing NULL values?

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

12 Which SQL clause filters rows according to a condition?

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

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

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

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

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

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

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

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

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

17 What is a SQL Server view?

SQL Server Views Easy
A. A physical copy of an entire database
B. A command that deletes table rows
C. A saved virtual table based on a query
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. Simple view
B. Indexed 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 PROC EmployeeView AS
C. CREATE INDEX EmployeeView AS
D. CREATE TABLE EmployeeView AS

20 What is a stored procedure in SQL Server?

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

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. Index fragmentation
B. Table normalization
C. Data redundancy
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. UNIQUE
B. DEFAULT
C. COMPUTED
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. Graph database
C. Document database
D. Key-value database

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

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

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. MODIFY TABLE Orders 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. PRIMARY KEY
B. DEFAULT
C. CHECK
D. FOREIGN 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 HAVING COUNT(*) > 5;
C. SELECT DepartmentID FROM Employees GROUP BY DepartmentID WHERE 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 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. LEFT JOIN Orders
B. INNER JOIN Orders
C. RIGHT JOIN Customers
D. CROSS 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. Cross-join Employees without aliases
B. Union Employees with itself
C. Group Employees by ManagerID
D. Self-join Employees using two 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. Restrict access to selected data
B. Replace all table constraints
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 filtered nonclustered index
B. A full-text index
C. A unique clustered index
D. A columnstore index

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

User Defined Views Medium
A. SELECT VIEW ActiveProducts AS ProductID, Name FROM Products WHERE IsActive = 1;
B. CREATE VIEW ActiveProducts AS SELECT ProductID, Name FROM Products WHERE IsActive = 1;
C. CREATE ActiveProducts VIEW 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 centralizes reusable database logic
B. It guarantees every query uses an index
C. It converts tables into temporary files
D. It removes the need for permissions

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. CALL GetOrders CustomerID AS 25;
C. SELECT GetOrders FROM CustomerID = 25;
D. EXEC GetOrders @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. FOREIGN KEY (EndDate >= StartDate)
C. DEFAULT (EndDate >= StartDate)
D. CHECK (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 EXISTS (SELECT 1 FROM Orders o WHERE o.CustomerID = c.CustomerID)
B. WHERE c.CustomerID BETWEEN (SELECT CustomerID FROM Orders)
C. WHERE ALL (SELECT CustomerID FROM Orders) = c.CustomerID
D. WHERE ANY (SELECT CustomerID FROM Orders) <> 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 CHECK OPTION
B. WITH RECOMPILE
C. WITH ENCRYPTION
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 DEFAULT
B. @OrderID int RETURN
C. @OrderID int OUTPUT
D. @OrderID int IDENTITY

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. First Normal Form only
B. Second Normal Form only
C. Boyce-Codd Normal Form
D. Third 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 invisible to nested procedures but visible to dynamic SQL
B. It is visible only within the statement that created it
C. It is visible to the creating procedure and nested procedures
D. It is visible to every session until explicitly dropped

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

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

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 is processed before the alias exists; use a derived table or repeat the expression
B. SELECT aliases require aggregation; add GROUP BY Quantity, UnitPrice
C. Total is reserved by SQL Server; delimit the alias using square brackets
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 EXISTS (SELECT 1 FROM B WHERE B.ID <> A.ID)
B. WHERE A.ID != (SELECT DISTINCT B.ID FROM B)
C. WHERE A.ID <> ALL (SELECT ISNULL(B.ID, A.ID) FROM B)
D. WHERE NOT EXISTS (SELECT 1 FROM B WHERE B.ID = A.ID)

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. 9 rows
B. 10 rows
C. 11 rows
D. 8 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. Descending order only when the view uses a clustered primary key
C. Stable order until statistics or indexes on the base table change
D. No ordering guarantee unless the outer query has its own ORDER BY

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

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

Introduction to Stored Procedure Hard
A. RETURN supplies any SQL type; output parameters are restricted to integers
B. RETURN supplies a complete result set; SELECT supplies only status codes
C. RETURN and output parameters both support only one nullable integer value
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. Continue issuing writes before committing the transaction normally
B. Commit the transaction and then reset the session error state
C. Create a savepoint and commit only the operations before it
D. Roll back the transaction and then propagate or handle the error

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 WITH SCHEMABINDING to the procedure
C. Add DISTINCT to the affected statement
D. Add OPTION (RECOMPILE) to the affected statement

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_SEED('Orders')
B. SCOPE_IDENTITY()
C. @@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 SUM(Amount) >= 3 AND COUNT(Amount) >= 2
C. HAVING COUNT(Amount) >= 3 AND COUNT(*) >= 2
D. HAVING COUNT(*) >= 3 AND COUNT(Amount) >= 2