Which of the following best describes a primary key constraint in SQL?
Which of the following constraints enforces a column or a set of columns to have unique values within a table?
Which of the following constraints allows you to provide a default value for a column if no value is specified during an insertion?
Consider the following SQL table definition:
CREATE TABLE Employees (
ID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
DepartmentID INT FOREIGN KEY REFERENCES Departments(ID)
);
What would be the output of the following INSERT statement?
INSERT INTO Employees (ID, Name, DepartmentID) VALUES (1, 'John Doe', 100);
Consider the following SQL table definition:
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
OrderDate DATE DEFAULT GETDATE()
);
What would be the output of the following INSERT statement?
INSERT INTO Orders (OrderID) VALUES (1);
Consider the following SQL table definition:
CREATE TABLE Students (
ID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Age INT CHECK (Age > 0)
);
What would be the output of the following INSERT statement?
INSERT INTO Students (ID, Name, Age) VALUES (1, 'Alice', 18);
Consider the following SQL table definition:
CREATE TABLE Employees (
ID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
DepartmentID INT,
CONSTRAINT FK_Department FOREIGN KEY (DepartmentID) REFERENCES Departments(ID)
);
What would happen if the following DELETE statement is executed?
DELETE FROM Departments WHERE ID = 1;
Consider the following SQL table definition:
CREATE TABLE Customers (
ID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Discount DECIMAL(4, 2) DEFAULT 0.00 CHECK (Discount >= 0 AND Discount <= 1)
);
Which of the following statements about the Customers table is correct?
Consider the following SQL table definition:
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
CustomerID INT FOREIGN KEY REFERENCES Customers(ID),
OrderDate DATE DEFAULT GETDATE()
);
Which of the following statements about the Orders table is correct?
Consider the following SQL table definition:
CREATE TABLE Products (
ID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
Price DECIMAL(10, 2) CHECK (Price > 0),
CategoryID INT,
CONSTRAINT FK_Category FOREIGN KEY (CategoryID) REFERENCES Categories(ID)
);
Which of the following statements about the Products table is correct?
Consider the following SQL table definition:
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
OrderDate DATE,
CustomerID INT,
CONSTRAINT FK_Customer FOREIGN KEY (CustomerID) REFERENCES Customers(ID) ON DELETE CASCADE
);
What happens when a customer is deleted from the Customers table?
Consider the following SQL table definition:
CREATE TABLE Employees (
ID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
ManagerID INT,
CONSTRAINT FK_Manager FOREIGN KEY (ManagerID) REFERENCES Employees(ID)
);
Which type of relationship is represented by the foreign key constraint in this table?
Consider the following SQL table definition:
CREATE TABLE Employees (
ID INT PRIMARY KEY,
Name VARCHAR(50) NOT NULL,
ManagerID INT,
CONSTRAINT FK_Manager FOREIGN KEY (ManagerID) REFERENCES Employees(ID) ON UPDATE CASCADE
);
What happens when the ID of a manager is updated in the Employees table?