eMonk Posted March 28, 2009 Share Posted March 28, 2009 I get this error when trying to run this mysql command: mysql -h xxx -u xxx -p books < /path/to/book_insert.sql book_insert.sql use books; insert into customers values (3, 'Julie Smith', '25 Oak Street', 'Airport West'), (4, 'Alan Wong', '1/47 Haines Avenue', 'Box Hill'), (5, 'Michelle Arthur', '357 North Road', 'Yarraville'); insert into orders values (NULL, 3, 69.98, '2007-04-02'), (NULL, 1, 49.99, '2007-04-15'), (NULL, 2, 74.98, '2007-04-19'), (NULL, 3, 24.99, '2007-05-01'); insert into books values ('0-672-31697-8', 'Michael Morgan', 'Java 2 for Professional Developers', 34.99), ('0-672-31745-1', 'Thomas Down', 'Installing Debian GNU/Linux', 24.99), ('0-672-31509-2', 'Pruitt, et al.', 'Teach Yourself GIMP in 24 Hours', 24.99), ('0-672-31769-9', 'Thomas Schenk', 'Caldera OpenLinux System Administration Unleashed', 49.99); insert into order_items values (1, '0-672-31697-8', 2), (2, '0-672-31769-9', 1), (3, '0-672-31769-9', 1), (4, '0-672-31509-2', 1), (5, '0-672-31745-1', 3); insert into book_reviews values ('0-672-31697-8', 'The Morgan book is clearly written and goes well beyond most of the basic Java books out there.'); bookorama.sql create table customers ( customerid int unsigned not null auto_increment primary key, name char(50) not null, address char(100) not null, city char(30) not null ); create table orders ( orderid int unsigned not null auto_increment primary key, customerid int unsigned not null, amount float(6,2), date date not null ); create table books ( isbn char(13) not null primary key, author char(50), title char(100), price float(4,2) ); create table order_items ( orderid int unsigned not null, isbn char(13) not null, quantity tinyint unsigned, primary key (orderid, isbn) ); create table book_reviews ( isbn char(13) not null primary key, review text ); any ideas? i'm new to mysql and this is my first experiment. Quote Link to comment https://forums.phpfreaks.com/topic/151500-solved-error-1062-23000-at-line-3-duplicate-entry-3-for-key-1/ Share on other sites More sharing options...
POG1 Posted March 28, 2009 Share Posted March 28, 2009 It needs to auto increment. Quote Link to comment https://forums.phpfreaks.com/topic/151500-solved-error-1062-23000-at-line-3-duplicate-entry-3-for-key-1/#findComment-795718 Share on other sites More sharing options...
eMonk Posted March 28, 2009 Author Share Posted March 28, 2009 thanks POG1 but where do i add that? sorry mysql newbie here. Quote Link to comment https://forums.phpfreaks.com/topic/151500-solved-error-1062-23000-at-line-3-duplicate-entry-3-for-key-1/#findComment-795915 Share on other sites More sharing options...
eMonk Posted March 28, 2009 Author Share Posted March 28, 2009 update: i had some typos in the book_insert.sql file during my 1st attempt. in result duplicate data was detected when i performed the same query again. i used TRUNCATE TABLE tablename; then performed the query & now it works. Quote Link to comment https://forums.phpfreaks.com/topic/151500-solved-error-1062-23000-at-line-3-duplicate-entry-3-for-key-1/#findComment-796008 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.