E
E
Evgeny Petryaev2020-02-04 12:32:33
Database design
Evgeny Petryaev, 2020-02-04 12:32:33

Design a table relationship?

There is this table:

CREATE TABLE `users` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `nickname` varchar(30) DEFAULT NULL,
  `email` varchar(30) DEFAULT NULL,
  `password` varchar(32) DEFAULT NULL,
  `reg_date` datetime DEFAULT CURRENT_TIMESTAMP,
  PRIMARY KEY (`id`),
  UNIQUE KEY `nickname` (`nickname`)
)

Another one is required, it must also contain users and other data, so is it better to take the id or nickname field?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Konstantin Tsvetkov, 2020-02-04
@tsklab

ID
UNIQUE KEY `nickname` (`nickname`)and `nickname` varchar(30) DEFAULT NULLmeans that there can be only one user without a nickname.

V
Vladimir Korotenko, 2020-02-04
@firedragon

Firstly, use an ID
; secondly, expand the mail field to 256 characters, make a unique index on it

I
Ivan Melnikov, 2020-02-04
@immelnikoff

so what is better to take the id or nickname field?

Take as a reference field of a foreign key of another table? In some DBMS, for example, in MySQL, it is not possible to assign a foreign key to a non-primary key (of another table).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question