T
T
theSever2018-07-06 22:32:23
SQL
theSever, 2018-07-06 22:32:23

Assign unique value to two columns?

In short, I want to create a database with columns id, name, tel, mail, txt
At the same time, so that id is filled in automatically when a new row is added, and most importantly, a duplicate value cannot be added to the name column , that is, if the name table already has a row named vasy1 , then a row with the same value in that column could not be added.
I tried to do this, but it gives an error:

CREATE TABLE `book` (
`id` INTEGER AUTOINCREMENT NOT NULL,
`name` TEXT NOT NULL,
`site` TEXT NULL,
`tel` TEXT NULL,
`mail` INTEGER NULL,
`txt` TEXT NULL,
PRIMARY KEY(id,name)
);

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Roman Mirilaczvili, 2018-07-06
@theSever

https://www.techonthenet.com/sqlite/unique.php

CREATE TABLE employees
( employee_id INTEGER PRIMARY KEY AUTOINCREMENT,
  last_name VARCHAR NOT NULL,
  first_name VARCHAR,
  hire_date DATE,
  CONSTRAINT name_unique UNIQUE (last_name, first_name)
);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question