By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
CREATE TABLE #Students(
[Name] varchar(50),
[Surname] varchar(50),
[Period] int,
[Sport] int,
[History] int,
[English] int,
[Geography] int)
ALTER TABLE #Students
ADD CONSTRAINT chk_period CHECK (Period IN (1,2,3,4))
INSERT INTO
#Students([Name],[Surname],[Period],[Sport],[History],[English],[Geography])
VALUES
('Mary','Brown',1,17,15,NULL,30)
1 rows affected
INSERT INTO
#Students([Name],[Surname],[Period],[Sport],[History],[English],[Geography])
VALUES
('Luke','Green',5,30,20,23,NULL)
Msg 547 Level 16 State 0 Line 1
The INSERT statement conflicted with the CHECK constraint "chk_period". The conflict occurred in database "tempdb", table "dbo.#Students___________________________________________________________________________________________________________000000000049", column 'Period'.
Msg 3621 Level 0 State 0 Line 1
The statement has been terminated.
SELECT *
FROM #Students
Name | Surname | Period | Sport | History | English | Geography |
---|---|---|---|---|---|---|
Mary | Brown | 1 | 17 | 15 | null | 30 |