Z
Z
Zubastik_12018-03-13 12:11:54
MySQL
Zubastik_1, 2018-03-13 12:11:54

In what cases it is necessary to add AUTO_INCREMENT when creating a table in a database?

Let's say I receive data via a third-party API in which there is already an id-shnik, but it is text. Do I need to add an INT (AUTO_INCREMENT) field, or can I use a text ID from json, taking into account the fact that I will need to make a selection from this table, and it is quite large.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis, 2018-03-13
@Zubastik_1

There is little initial data, what kind of data do you get, where do you save it, etc.
what kind of text id (is it a numeric format in the form of a string or just a string hash), how do you insert data to yourself from api, etc.,
if you have a json id this string hash, then it’s better to create your id field in your table as an increment and store json id in the hash field
if json id can be cast to int then, in principle, you can take it as the basis of the primary key (and here, in principle, you can even add an increment, nothing bad will happen )

D
d-stream, 2018-03-13
@d-stream

You can’t trust other people’s data (c), so you have to make your own uniqueizer. For example, the same auto-increment id

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question