Answer: The Specified Column List For The Primary Key Must Be Inside The Parentheses
Answer: The Specified Column List For The Primary Key Must Be Inside The Parentheses
TravelTrip ( TripID int NOT NULL, Complaint bit NOT NULL, CONSTRAINT PK_TravelTrip_TripID PRIMARY KEY CLUSTERED TripID (ASC) )
Answer: The specified Column List for the Primary Key must be inside the parentheses.
CONSTRAINT PK_TravelTrip_TripID PRIMARY KEY CLUSTERED(TripID ASC)
Bug Catcher 2 CREATE TABLE Sales.TravelTrip ( TripID int PRIMARY KEY CLUSTERED, TripName varchar(max) CONSTRAINT UC_TripName UNIQUE, Complaint bit NOT NULL)
Bug Catcher 3 CREATE TABLE Sales.TravelTrip ( TripID int NOT NULL, Complaint bit NOT NULL, CONSTRAINT PK_TravelTrip_TripID PRIMARY KEY CLUSTERED )
Answer: You need to specify Column List for the Primary Key.
Bug Catcher 4
CONSTRAINT pk_Cust_CustID PRIMARY KEY (CustID), CONSTRAINT ck_Cust_Gender CHECK (Gender='M' OR Gender='F')
Bug Catcher 5
CONSTRAINT pk_Cust_CustID PRIMARY KEY (CustID), CONSTRAINT ck_Cust_Gender CHECK (Gender= M OR Gender= F )
CONSTRAINT pk_Cust_CustID PRIMARY KEY (CustID), CONSTRAINT ck_Cust_Gender CHECK (Gender='M' OR Gender='F')
Bug Catcher 6 CREATE TABLE Sales.TravelTrip ( TripID int NOT NULL, StartDate datetime NOT NULL, EndDate datetime NOT NULL, CONSTRAINT PK_TravelTrip_TripID PRIMARY KEY CLUSTERED (TripID) ), CONSTRAINT ck_TravelTrip_EndDate CHECK (EndDate>=StartDate) GO Answer: Put both constraints
Bug Catcher 7 CREATE TABLE Sales.TravelTrip ( TripID int NOT NULL, StartDate datetime NOT NULL, EndDate datetime NOT NULL, Complaint bit NOT NULL DEFAULT, CONSTRAINT PK_TravelTrip_TripID PRIMARY KEY CLUSTERED (TripID) , CONSTRAINT ck_TravelTrip_EndDate CHECK (EndDate>=StartDate) ) GO
Bug Catcher 8 CREATE TABLE Sales.TravelTrip ( TripID int NOT NULL, StartDate datetime NOT NULL, EndDate datetime NOT NULL, Complaint bit NOT NULL DEFAULT(0), CONSTRAINT PK_TravelTrip_TripID PRIMARY KEY CLUSTERED (TripID) , CONSTRAINT ck_TravelTrip_EndDate CHECK (EndDate>+StartDate) ) GO
Bug Catcher 9 CREATE TABLE Sales.TravelTrip ( TripID int NOT NULL, StartDate datetime NOT NULL, EndDate datetime NOT NULL, Complaint bit NOT NULL, DEFAULT(0), CONSTRAINT PK_TravelTrip_TripID PRIMARY KEY CLUSTERED (TripID) , CONSTRAINT ck_TravelTrip_EndDate CHECK (EndDate>=StartDate) ) GO
Answer: When using a constraint inline with a column you dont need a comma.
CREATE TABLE Sales.Travel Bug Catcher 10 (TripID int NOT NULL, CustomerID int NOT NULL, LocationID int NOT NULL, StartDate datetime NOT NULL, EndDate datetime NOT NULL, Rating tinyint NOT NULL, Complaint bit NOT NULL DEFAULT (0), CONSTRAINT PK_Travel_TripID PRIMARY KEY CLUSTERED (TripID ASC), CONSTRAINT ck_Travel_EndDate CHECK (EndDate>StartDate), CONSTRAINT ck_Travel_Rating CHECK (Rating<=100) CONSTRAINT ck_Travel_Complaint CHECK ((Complaint=0) OR (Complaint=1 AND Rating <=90)) )
--Logical Bug
Bug Catcher 11
Bug Catcher 12
Answer: To add a new field you must specify the data type
ALTER TABLE dbo.Employee ADD CONSTRAINT DEFAULT 12 FOR CommissionRate WITH VALUES
Bug Catcher 13
ALTER TABLE dbo.Employee ADD CONSTRAINT df_Employee_CommissionRate DEFAULT 12 FOR CommissionRate FOR VALUES
Bug Catcher 14
ALTER TABLE dbo.Employee ADD CONSTRAINT df_Employee_CommissionRate DEFAULT 12 FOR CommissionRate WITH VALUES
ALTER TABLE dbo.Employee ADD CONSTRAINT fk_Employee_Location_LocationID FOREIGN KEY (LocationID) REFERENCES (Location.LocationID)
Bug Catcher 15
Answer: You need to reference the table and column name in parens.
ALTER TABLE dbo.Employee ADD CONSTRAINT fk_Employee_Location_LocationID FOREIGN KEY (LocationID) REFERENCES Location(LocationID)
ALTER TABLE dbo.Employee ADD CONSTRAINT fk_Employee_Location_LocationID FOREIGN KEY (LocationID) REFERENCES Employee(LocationID)
Bug Catcher 16
Bug Catcher 17 CREATE TABLE Sales.TravelTrip ( TripID int NOT NULL, StartDate datetime NOT NULL, EndDate datetime NOT NULL, Complaint bit NOT NULL DEFAULT(0), CONSTRAINT PK_TravelTrip_TripID PRIMARY KEY CLUSTERED (TripID) , CONSTRAINT ck_TravelTrip_EndDate CHECK (EndDate=>StartDate) ) GO
--Note: SSN is PRIMARY KEY --Note: (IGNORE_DUP_KEY = OFF) INSERT INTO [EmployeeHistory] SELECT * FROM Employee GO
Bug Catcher 18
INSERT INTO dbo.Employee VALUES ('369-152429','Alex','Smith','[email protected]',0) GO INSERT INTO [EmployeeHistory] SELECT * FROM Employee
Answer: Trying to insert all rows again will result in duplicate records on your primary key.