-2

Wherever I was looking for, I've never heard about that any SQL implementations would have an IS UNIQUE "command". Did I miss something? If I'm right, what is the reason?

In other words, why I can't state in SQL that a certain command, such as INSERT INTO (especially that) can be done only if a value is or is not considered UNIQUE?

Zoltán Schmidt
  • 1,286
  • 2
  • 28
  • 48
  • 6
    You do that with column restraints in the table itself, not in the SQL INSERT. Check the documentation for the specific DBMS you're using for the proper syntax to use with the column definition in CREATE TABLE. – Ken White Apr 07 '16 at 22:27

3 Answers3

1

Have a look at Unique constraint in SQl server.. That takes care of uniqueness while inserting in a table. Alternatively you can use 'IF NOT EXISTS' before inserting any value to check whether it exists in the table for that column or you can achieve the same by adding conditions in the where clause before inserting in the table..

Nagahornbill
  • 121
  • 7
  • 2
    There's no indication this poster is using SQL Server, which is why my comment to the question itself suggests reading the documentation for the DBMS they're using. – Ken White Apr 07 '16 at 22:39
1

Select queries can use the key word "distinct" to select unique items from a table

SELECT DISTINCT person_name FROM people WHERE age = 4;

For insertion you can also consider the INSERT IGNORE to do an insert ignore

INSERT IGNORE INTO people (values...)

0

Do you mean by CREATE UNIQUE INDEX index_name ON table_name (column_name)

shh
  • 91
  • 1