Am I breaking something if I set an autoincrement PK to 0?
0
votes
1
answer
1698
views
I have this table
CREATE TABLE
test_table
(
id
int unsigned NOT NULL AUTO_INCREMENT,
name
varchar(50) NOT NULL,
PRIMARY KEY (id
),
UNIQUE KEY name_UNIQUE
(name
)
) ENGINE=InnoDB;
Insert some records...
INSERT INTO test_table
(name
) VALUES ('a');
INSERT INTO test_table
(name
) VALUES ('b');
INSERT INTO test_table
(name
) VALUES ('c');
So I get records 1, 2 and 3 with values a, b and c respectively.
Now, I need to have a record with 0 as id
and empty string as name
. So I did this
INSERT INTO test_table
(id
, name
) VALUES ('0', '');
UPDATE test_table
SET id
='0' WHERE id
='4';
ALTER TABLE test_table
AUTO_INCREMENT = 4 ;
Do I have a guarantee that everything will continue to work properly? Table references, auto increment sequence, etc...
Asked by Matías Cánepa
(113 rep)
Oct 19, 2020, 08:32 PM
Last activity: Dec 9, 2024, 01:02 PM
Last activity: Dec 9, 2024, 01:02 PM