![]() ![]() ![]() ("KBC355","KBC Computers","Glasgow","014") Īfter changing type insert will work without problems. Supp_id varchar(30) NULL, - You can set length as you wish DROP TABLE suppliers - Will drop your old table I guess you are using InnoDB as table type, in this case query will run as transaction and it will rollback after first error(for this example it will be second row). With your table you can get the error like "Incorrect Integer Value", but depending on MySQL server configuration it can do conversion(string->int) automatically for your query string must become "0" as result of this it makes 2 rows with 0 as supp_id and get error Duplicate entry '0' for key 'PRIMARY'. MySQL (and some other databases) allow double quotes, but there is no reason to not use the standard. Single quotes are ANSI standard for string constants.I added a unique supplier name to the table and declared the id to be a auto_increment.Usually you want varchar() rather than char(), unless you really like lots of spaces at the end of strings.INSERT INTO Suppliers(supp_name, company_name, town, phone) SupplierId int NOT NULL auto_increment primary key, I suspect you want the following code: CREATE TABLE suppliers ( You have another id field that is the primary key, but given no value and not declared autoincrement. Because the leading characters are letters, the value is 0. In older versions of MySQL, I think the string values get silently converted to numbers. You have another id field that is the primary key, but given no value and not declared auto_increment. suppid is the primary key and declared as a number. Supp_id is the primary key and declared as a number. In your case, two possibilities come to mind: value The next value that will be used in the AUTOINCREMENT column. The insert itself is causing the duplication. In MySQL, the syntax to reset the AUTOINCREMENT column using the ALTER TABLE statement is: ALTER TABLE tablename AUTOINCREMENT value tablename The name of the table whose AUTOINCREMENT column you wish to reset. ![]() ![]() This occurs when you have a primary key but do not give it an initialization value. ![]()
0 Comments
Leave a Reply. |