Sobes.tech
Junior — Middle

Mis on võtmesõna UNIQUE eesmärk SQL-is ja millal seda kasutatakse?

sobes.tech AI

Vastus AI-lt

The keyword UNIQUE in SQL is used to constrain a column or set of columns so that all values in them are unique, meaning they do not repeat.

This helps ensure data integrity, for example, to prevent duplicates in a table for a specific field.

Example of usage:

CREATE TABLE users (
    id INT PRIMARY KEY,
    email VARCHAR(255) UNIQUE
);

In this example, the email column cannot contain duplicate values.

UNIQUE is often used for fields that must be unique but are not primary keys, such as phone numbers, usernames, serial numbers, etc.