N
N
Nikita Kossman2020-02-13 19:41:17
JavaScript
Nikita Kossman, 2020-02-13 19:41:17

What to specify when creating a MYSQL table?

Hello. I would like to ask one question. I searched all over the Internet, but I did not find the necessary information.
I have 4 fields in the table:
1. id
2. username
3. email
4. password
And the question is, what values ​​and types should be specified for these fields? I'm still a beginner, so I don't quite understand.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
N
Nikolai Eremeev, 2019-06-07
@Garfields

// здесь принимаем функции как параметры (yes - showOk, no - showCancel)
function ask(question, yes, no) {
    // confirm(question) выполняется так как нам нужен результат из if (true или false)
    // Если confirm(question) - true (нажмете Ок), то выполниться yes() (showOk), иначе выполниться no() (showCancel)
    if (confirm(question)) yes()
    else no();
  }

function showOk() {
  alert( "Вы согласились." );
}

function showCancel() {
  alert( "Вы отменили выполнение." );
}

// здесь передаем функции showOk и showCancel в параметры ask (первый параметр - текст сообщения в confirm)
ask("Вы согласны?", showOk, showCancel);

S
SagePtr, 2019-06-07
@SagePtr

In short - we have a function that takes three parameters - a message text and two callbacks.
The function shows a message with "yes" / "no" buttons (it depends on the browser, each formats the message in its own way, the text of the buttons and the location may also differ), and if the user clicks yes, it pulls the first callback, if it clicks no, it pulls the second callback.
And in the callbacks we pass two functions, each of which shows a message (different).

G
granty, 2020-02-14
@sodbroil

Nikita Kossman ,

1. id

id INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY
then the id will increase by 1 each time a new record is inserted. And it will be used to make a key for "quick fetching" records by id
2. username

username VARCHAR(64)
where 64 is the maximum name length, longer ones will be truncated. You can reduce/enlarge according to your realities.
The TEXT field is bad to use, it has a size of 65535 characters per record, the table will swell a lot.
3. email

email VARCHAR(129) UNIQUE NOT NULL
129 characters - the maximum possible length of emails according to the current RFC
UNIQUE NOT NULL will guarantee the uniqueness of all emails in the table - the database will not allow to write the same values ​​and will throw an error.
4.password

password VARCHAR(32)
if you store md5 from password there. Or change 32 to fit whatever you're going to store there, since you'll need to store the "salt" somewhere. (256 is the maximum for VARCHAR).
PS: It's better not to store passwords in the database at all (even salted and encrypted ones), in the 21st century they are not needed for user authorization.
Well, and make keys / indexes for the username and email fields, according to your logic for selecting from the table (which fields in the WHERE clause will you make selections for).

R
Ronald McDonald, 2020-02-13
@Zoominger

You can use int for id, text for the rest. This is not the most super-optimal option, but it is not critical.
Or do you want exactly the table creation line?

L
Lazy @BojackHorseman MySQL, 2020-02-13
Tag

read carefully until complete memorization

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question