In PHP, what considerations should be made when setting up auto_increment for primary keys in a database table, and how does it relate to the issue of duplicate entries for key 2?
When setting up auto_increment for primary keys in a database table, it is important to ensure that the field is set as the primary key and auto_increment. This will automatically generate a unique key for each new entry, preventing duplicate entries for the key. To avoid issues with duplicate entries for key 2, make sure that the auto_increment value starts at a number greater than the existing keys in the table.
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL
);
ALTER TABLE users AUTO_INCREMENT = 1001;