![]() |
MYSQL Help Needed
ERROR 1062 (23000) at line 3: Duplicate entry '3' for key 1
I get this error when trying to run the following mysql command: mysql -h xxx -u xxx -p books < /path/to/book_insert.sql book_insert.sql Code:
use books; Code:
create table customers |
If you have a unique index defined on one of your fields and then you try to insert duplicate values into that table the item with a unique key will cause it to fail.
Looks like you have isbn defined as a primary key on your order_items table, which means you will never be able to insert the same book twice. EDIT: on closer inspection - the key is actually defined on the combination of order id and isbn, so that should be okay actually. You probably have already entered some of this data before and are now tyring to enter duped data where it is uniquely keyed. |
thx for your response. there is no data in the books database. i was told elsewhere that it needs to auto increment but he didn't say where. this code is straight from a php & mysql book. first mysql lesson & i'm stuck lol.
|
edit: there is data in these tables, werid. guess i will delete this database & try readding info.
|
first rule in developing a database ...when loading info for the first time delete * from table;
or drop the table and recreate it put it in your script as the first thing |
thx mikesouth.. i used TRUNCATE TABLE tablename; then performed the above command & now it works. during the 1st attempt my insert_book.sql file had some typos. in result duplicate data was detected.
|
btw isn't there a way to delete ALL data from a database? deleting data in tables one by one is a bit tedious. good thing i didn't have too many.
|
Quote:
drop database dbname; create dbname; use dbname; create table....... etc etc etc |
All times are GMT -7. The time now is 04:01 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123