Insert Sql Server

2

I have a multi-column table. The unique identifier is the ID, but my question is as follows:

I have a version column , in it I want to be inserted only one value without repetition. How can I implement this?

    
asked by anonymous 17.05.2017 / 17:02

1 answer

2

You should make your column have a constraint of type unique .

In an editor such as SQL Server Management Studio , you should go to table indexes and create a unique index for the column.

I already saw code, you do something like this:

CREATE UNIQUE INDEX NomeDoIndice ON dbo.[Tabela com várias colunas]([Versão]);

Note that the code above assumes that the table actually calls Tabela com várias colunas and that the column name actually is Versão . You can use the actual names of your table and column, and the index name can be any arbitrary name.

If you create a single index, every time you try to insert a record into the table with a value in the version column that already exists, SQL will raise an error. The error message will explain that the table does not allow repetition in that column.

    
17.05.2017 / 18:14