I have been struggling with this issue for some time at my job and I need some help.
I have 2 tables, one with a ton of information and other where part of the information should be, i need to move a single column to a table already created with some codes to identify every row that is going to be inserted (mostly users) and it throws an error because it says that I must insert an id also, but the id already are there.
let's say I have these tables:
table_information
admin_name|admin_address|admin_phone|admin_mail
john |home |111111111 |something@mail.com
pete |house |222222222 |else@mail.com
mike |crib |333333333 |my@mail.com
ryan |someplace |444444444 |custom@mail.com
daniel |somewhere |555555555 |user@mail.com
bruce |anywhere |666666666 |bruce@mail.com
dave |everywhere |777777777 |dave@mail.com
table_admin
admin_id|admin_name
1 |
2 |
3 |
4 |
5 |
6 |
7 |
and I need to move the column of the user names to the table users that has the codes so the result must be something like this:
table_information
admin_name|admin_address|admin_phone|admin_mail
john |home |111111111 |something@mail.com
pete |house |222222222 |else@mail.com
mike |crib |333333333 |my@mail.com
ryan |someplace |444444444 |custom@mail.com
daniel |somewhere |555555555 |user@mail.com
bruce |anywhere |666666666 |bruce@mail.com
dave |everywhere |777777777 |dave@mail.com
table_admin
admin_id|admin_name
1 | john
2 | pete
3 | mike
4 | ryan
5 | daniel
6 | bruce
7 | dave
the information is coming from a big database (around 1500 rows) where the admin names are repeated, therefore I have been using the select distinct to filter some of the duplicate rows.
The way I've been doing it is like this:
INSERT INTO table_admin (admin_name)
SELECT DISTINCT admin_name FROM table_information
And i obtain this:
Cannot insert the value NULL into column 'admin_id' column does not allow nulls. INSERT fails.
Also important is that the column admin_id
from the table table_admin
could not be identity (or auto increment) so the id's could not be automatically generated (I would have done it this way, but it's the way they work here).
Am I lacking something? doing something wrong? Let me know some suggestions, or solutions for this problem that is driving me crazy please.
Thanks in advance for reading.