0
When entering the data in my SQL table everything happens normal.
However, when trying to insert for the second time, with the same value in id
which is the main field of the table, it returns the following error:
Duplcate entry '156' for key 'PRIMARY'
.
However, I want my system to insert a new data line that has the same ID. How do I make this Primary key 'duplicate' ?
SQL:
CREATE TABLE IF NOT EXISTS `controledegm` (
`char_id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`char_name` varchar(255) NOT NULL,
`item_id` int(11) NOT NULL,
`item_name` varchar(255) NOT NULL,
`item_quantidade` int(11) NOT NULL,
`data` varchar(20) DEFAULT NULL,
`hora` varchar(20) NOT NULL,
PRIMARY KEY (`char_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=150007 ;
In this case you don’t need Primary Key, the correct thing is you create the table without setting it that everything will go well.
– Math
And how I create without defining her?
– GGirotto
Post the sql you used to create the table.
– ramaral
I edited in the content of the question
– GGirotto
You already have the primary key as
AUTO_INCREMENT
. In Insert you should not assign value to it. Post Insert/Update giving the error.– ramaral
@ramaral ta but in case just remove this AUTO_INCREMENT... In my case the only problem is that all my columns may come to repeat their value, and the key Primary cannot be repeated, so the question is whether there is a way to create a table without this primary key or should I create a column only to store this primary key...
– GGirotto
I edited my answer.
– ramaral
@Ggirotto: by definition a primary key is a field whose value uniquely identifies each row of a table, so it cannot exist in its table two rows with the same value for primary key.
– anonimo