I'm currently working on an assignment and have run into an issue.
I get an error:
Msg 8135, Level 16, State 0, Line 41
Table level constraint or index does not specify column list, table 'Sessions'.
I've run through it a million times, but I cannot find out where the issue arises. I believe I AM specifying the columns in both table-level statements, so I am at a loss.
Here is the code:
CREATE TABLE Class
(
-- Column specifications and constraints--
ClassID NCHAR(6) NOT NULL,
ClassDescription NVARCHAR(50) NOT NULL,
--Table constraints--
CONSTRAINT pk_Class_ClassID
PRIMARY KEY (ClassID) --ClassID is the primary key in the Class table, done as a table constraint
)
CREATE TABLE Riders
(
-- Column specifications and constraints--
RiderID INT NOT NULL IDENTITY(10, 1) --RiderID auto-fills in the value, starting at 10, incrementing by 1
CONSTRAINT pk_Riders_RiderID PRIMARY KEY, --RiderID is the primary key in the Riders table
[Name] NVARCHAR(50) NOT NULL
CONSTRAINT chk_Riders_Name CHECK (LEN([Name]) > 4), --Name must be longer than 4 letters
ClassID NCHAR(6) NULL,
--Table constraints--
CONSTRAINT fk_Riders_Class
FOREIGN KEY (ClassID) REFERENCES Class (ClassID)
)
CREATE TABLE [Sessions]
(
-- Column specifications and constraints--
RiderID INT NOT NULL,
BikeID NCHAR(6) NOT NULL,
SessionDate DATETIME NOT NULL
CONSTRAINT chk_Sessions_SessionDate CHECK (SessionDate > '1 Sep 2017'), --SessionDate must be AFTER September 1, 2017
Laps INT NULL,
-- Table constraints--
CONSTRAINT pk_Sessions_RiderID_BikeID_SessionDate
PRIMARY KEY (RiderID, BikeID, SessionDate), --RiderID, BikeID, SessionDate is the composite primary key for the Sessions table
INDEX CI_Sessions_RiderID_BikeID ON [Sessions] (RiderID, BikeID) --Index RiderID and BikeID
)
CREATE TABLE Bikes
(
-- Column specifications and constraints--
BikeID NCHAR(6) NOT NULL
CONSTRAINT chk_Bikes_BikeID CHECK (BikeID LIKE '[0-9][0-9][0-9][HYS]-[AP]') --BikeID in format ###X-A # = 0 - 9, X = H(Honda), Y(Yamaha), S(Suzuki), A = A(AM), P(PM)
CONSTRAINT pk_Bikes_BikeID PRIMARY KEY, --BikeID is the primary key in the Bikes table
StableDate DATE NOT NULL
CONSTRAINT def_Bikes_StableDate DEFAULT GETDATE()
)
ALTER TABLE [Sessions]
ADD CONSTRAINT chk_Sessions_Laps CHECK (Laps >= 10)
ALTER TABLE [Sessions]
ADD CONSTRAINT fk_Sessions_Riders
FOREIGN KEY (RiderID) REFERENCES Riders (RiderID)
ALTER TABLE [Sessions]
ADD CONSTRAINT fk_Sessions_Bikes
FOREIGN KEY (BikeID) REFERENCES Bikes (BikeID)
Any help is appreciated!!
This error can occur if you use the keyword "Index" or "index" as a column name in your sql table. To fix this, use "indx" or something else.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With