Which of the following is the best practice for naming a primary key constraint on a table named Employees?
Think about clarity and consistency in naming constraints.
Using PK_Employees clearly indicates it is a primary key constraint on the Employees table, following common naming conventions.
Given the following SQL query to list constraints on the Orders table, what is the name of the foreign key constraint?
SELECT constraint_name, constraint_type FROM information_schema.table_constraints WHERE table_name = 'Orders';
Assume the output is:
constraint_name | constraint_type ---------------------|---------------- PK_Orders | PRIMARY KEY FK_Orders_Customers | FOREIGN KEY CHK_OrderAmount | CHECK
Look for the constraint type FOREIGN KEY.
The foreign key constraint is named FK_Orders_Customers, which follows the convention FK_[Table]_[ReferencedTable].
Which SQL statement correctly creates a unique constraint named UQ_Products_SKU on the SKU column of the Products table?
Remember the order: ADD CONSTRAINT <name> UNIQUE (columns).
Option A uses the correct syntax: ADD CONSTRAINT <name> UNIQUE (column). Other options have syntax errors.
In a database with hundreds of tables, which naming convention for foreign key constraints helps optimize readability and maintenance?
Think about how names help identify relationships quickly.
Using FK_[ChildTable]_[ParentTable] clearly shows which table has the foreign key and which table it references, aiding maintenance.
Consider this SQL statement:
ALTER TABLE Customers ADD CONSTRAINT PK_Customers PRIMARY KEY (CustomerID);
Later, this statement fails:
ALTER TABLE Customers ADD CONSTRAINT PK_Customers PRIMARY KEY (CustomerID);
What is the most likely cause of the error?
Think about what happens if you try to add a constraint with a duplicate name.
Constraint names must be unique per table. Trying to add a constraint with an existing name causes an error.