Saturday 11 May 2019

MSSQL - Create table that allows to have only 1 (one) row


watch this example on YouTube

The following table will not allow user to enter more than 1 record

CREATE Table SomeTable(
    Locking Char(1) not null,
    SomeID int,
    constraint PK_SomeTable Primary Key (Locking),
    constraint CK_SomeTable_Locked Check (Locking='X')
)
Insert into SomeTable (Locking, SomeID) Values ('X', 1)
Select * From SomeTable

No comments:

Post a Comment