A
A
Albert Kazan2019-09-13 18:42:11
MySQL
Albert Kazan, 2019-09-13 18:42:11

How to create a table where the records match the records from the old table?

Right from the start, there is a typical users table. It had all sorts of login data, registration date and nickname.
Now it's a little overgrown with the whole beginning and you need to put other data, for example, a phone number or Last Name. They will rarely be used in practice, so I want to put them in a separate table. There will be separate data fields, but the same id (primary index). In the right places on the site through JOIN, it's easy to display.
How to synchronously insert all users into the second table so that the id's match? Is such synchronization possible?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
Lazy @BojackHorseman MySQL, 2019-09-13
Tag

do you need a new table? maybe just add fields to the old one?

N
Nujabes37, 2019-09-13
@Nujabes37

It will not be reliable to hope that their id will always match) Better add a separate usermeta table and link them to user_id)

S
Sergey c0re, 2019-09-14
@erge

create table duplicate: insert rows:

INSERT IGNORE
    INTO users2 (id_user, name, ................)
SELECT
    id_user, name, ..................
FROM
    users

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question