clear markdown feedback
clear markdown feedback
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 3364508 fiddles created (36241 in the last week).

CREATE TABLE #Students( [Name] varchar(50), [Surname] varchar(50), [Period] int, [Sport] int, [History] int, [English] int, [Geography] int)
 hidden batch(es)


ALTER TABLE #Students ADD CONSTRAINT chk_period CHECK (Period IN (1,2,3,4))
 hidden batch(es)


INSERT INTO #Students([Name],[Surname],[Period],[Sport],[History],[English],[Geography]) VALUES ('Mary','Brown',1,17,15,NULL,30)
1 rows affected
 hidden batch(es)


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.
 hidden batch(es)


SELECT * FROM #Students
Name Surname Period Sport History English Geography
Mary Brown 1 17 15 30
 hidden batch(es)