I have a question how to create constraints for repeating non-key field values? fields: -number (key, autoincrement) -year -discipline -course -flow etc

I want the combination year + discipline + course + flow to be unique, but at the same time, what would be the key field as well as the number field! (Of course, you can make these fields key, but I have to work with the number field in the future, and it should be key).

Tell me how to do this? (I get confused with triggers ..... I can’t do it with restrictions so that all these fields are unique)

    2 answers 2

    UNIQUE declarative constraint solves the problem:

    alter table имя_таблицы add constraint uydcp unique(год,дисциплина,курс,поток) 
    • Thank you very much, it works ... :)))) - Rakzin Roman
    • @ Roman Rakzin, if you answered correctly. It is worth noting the question as taken. - Nicolas Chabanovsky
    • Ok)) ...... - Rakzin Roman

    Add a unique index for these fields: year + discipline + course + flow.

     CREATE UNIQUE NONCLUSTERED INDEX IX_Table ON [Table] (Год, Дисциплина, Курс, Поток ) ALTER TABLE dbo.Table SET (LOCK_ESCALATION= TABLE) 
    • Thank you very much)), I did a little wrong .... works ..... wrote: dbo is not a known ALTER TABLE parameter, I tried to write ALTER TABLE dbo.Table SET (LOCK_ESCALATION = [base_name] .dbo.table_name) ... and without dbo (just a table) .... but cursed all the same ... Opened the table-Indices-create a new one, and in the "add" chose the required fields Thank you ... - Rakzin Roman