This is a discussion on insert problem.... within the MySQL forums, part of the Database Server Software category; --> CREATE TABLE `php_mysql`.`contacts` ( `id` int(6) NOT NULL auto_increment, `first` varchar(15) NOT NULL, `last` varchar(15) NOT NULL, `phone` varchar(20) ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| CREATE TABLE `php_mysql`.`contacts` ( `id` int(6) NOT NULL auto_increment, `first` varchar(15) NOT NULL, `last` varchar(15) NOT NULL, `phone` varchar(20) default NULL, `mobile` varchar(20) default NULL, `fax` varchar(20) default NULL, `email` varchar(30) default NULL, `web` varchar(30) default NULL, PRIMARY KEY (`id`), UNIQUE KEY `id` (`id`), UNIQUE KEY `last_name` (`last`), KEY `id_2` (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1; insert into table contacts values '','steve','cristaldi','','','','',''); You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table contacts values ('','steve','kurowski','','','','','')' at line 1 |
| |||
| removed keyword table from insert, got error as follows Out of range value adjusted for column 'id' at row 1 someone wrote: > CREATE TABLE `php_mysql`.`contacts` ( > `id` int(6) NOT NULL auto_increment, > `first` varchar(15) NOT NULL, > `last` varchar(15) NOT NULL, > `phone` varchar(20) default NULL, > `mobile` varchar(20) default NULL, > `fax` varchar(20) default NULL, > `email` varchar(30) default NULL, > `web` varchar(30) default NULL, > PRIMARY KEY (`id`), > UNIQUE KEY `id` (`id`), > UNIQUE KEY `last_name` (`last`), > KEY `id_2` (`id`) > ) ENGINE=InnoDB DEFAULT CHARSET=latin1; > > insert into table contacts values '','steve','cristaldi','','','','',''); > > > You have an error in your SQL syntax; check the manual that corresponds > to your MySQL server version for the right syntax to use near 'table > contacts values ('','steve','kurowski','','','','','')' at line 1 |
| |||
| someone wrote: > CREATE TABLE `php_mysql`.`contacts` ( > `id` int(6) NOT NULL auto_increment, > `first` varchar(15) NOT NULL, > `last` varchar(15) NOT NULL, > `phone` varchar(20) default NULL, > `mobile` varchar(20) default NULL, > `fax` varchar(20) default NULL, > `email` varchar(30) default NULL, > `web` varchar(30) default NULL, > PRIMARY KEY (`id`), > UNIQUE KEY `id` (`id`), > UNIQUE KEY `last_name` (`last`), > KEY `id_2` (`id`) > ) ENGINE=InnoDB DEFAULT CHARSET=latin1; > > insert into table contacts values '','steve','cristaldi','','','','',''); > > > You have an error in your SQL syntax; check the manual that corresponds > to your MySQL server version for the right syntax to use near 'table > contacts values ('','steve','kurowski','','','','','')' at line 1 If you copied and pasted the above from some database client, then it is possible the error is due to the back-tick characters shown in your create table statement - They should be single quotes (') instead. I would start with those and see what you get from there. You might even try to remove the 'ENGINE.....' part. Cheers, Chris Val |
| |||
| Chris ( Val ) wrote: > someone wrote: > >>CREATE TABLE `php_mysql`.`contacts` ( >> `id` int(6) NOT NULL auto_increment, >> `first` varchar(15) NOT NULL, >> `last` varchar(15) NOT NULL, >> `phone` varchar(20) default NULL, >> `mobile` varchar(20) default NULL, >> `fax` varchar(20) default NULL, >> `email` varchar(30) default NULL, >> `web` varchar(30) default NULL, >> PRIMARY KEY (`id`), >> UNIQUE KEY `id` (`id`), >> UNIQUE KEY `last_name` (`last`), >> KEY `id_2` (`id`) >>) ENGINE=InnoDB DEFAULT CHARSET=latin1; >> >>insert into table contacts values '','steve','cristaldi','','','','',''); >> >> >>You have an error in your SQL syntax; check the manual that corresponds >>to your MySQL server version for the right syntax to use near 'table >>contacts values ('','steve','kurowski','','','','','')' at line 1 > > > If you copied and pasted the above from some database > client, then it is possible the error is due to the back-tick > characters shown in your create table statement - They > should be single quotes (') instead. > > I would start with those and see what you get from there. > You might even try to remove the 'ENGINE.....' part. > > Cheers, > Chris Val > Chris, No, the back-ticks are correct syntax. These are column names, not values. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
| |||
| someone wrote: > removed keyword table from insert, got error as follows > > Out of range value adjusted for column 'id' at row 1 > > > someone wrote: > >> CREATE TABLE `php_mysql`.`contacts` ( >> `id` int(6) NOT NULL auto_increment, >> `first` varchar(15) NOT NULL, >> `last` varchar(15) NOT NULL, >> `phone` varchar(20) default NULL, >> `mobile` varchar(20) default NULL, >> `fax` varchar(20) default NULL, >> `email` varchar(30) default NULL, >> `web` varchar(30) default NULL, >> PRIMARY KEY (`id`), >> UNIQUE KEY `id` (`id`), >> UNIQUE KEY `last_name` (`last`), >> KEY `id_2` (`id`) >> ) ENGINE=InnoDB DEFAULT CHARSET=latin1; >> >> insert into table contacts values '','steve','cristaldi','','','','',''); >> >> >> You have an error in your SQL syntax; check the manual that >> corresponds to your MySQL server version for the right syntax to use >> near 'table contacts values ('','steve','kurowski','','','','','')' >> at line 1 It's because you're trying to insert an empty string in the id column. This is not a valid int value. You should always specify the columns when you do an INSERT - that way if later you need to add a column to the table all of your INSERTs will not break (as long as you have a default value for the column). As it is, if you add a column your INSERT will fail. insert into contacts(first, last, phone, mobile, fax, email, web) values ('steve','cristaldi','','','','',''); Otherwise, if you really insist on doing it without the column names, insert into contacts values (NULL, 'steve','cristaldi','','','','',''); The NULL value tells an auto_increment column to increment to the next value. 0 should work also, but I haven't tried it. -- ================== Remove the "x" from my email address Jerry Stuckle JDS Computer Training Corp. jstucklex@attglobal.net ================== |
| ||||
| On Fri, 22 Sep 2006 02:12:10 GMT, someone wrote: > removed keyword table from insert, got error as follows > > Out of range value adjusted for column 'id' at row 1 > > > someone wrote: > >> CREATE TABLE `php_mysql`.`contacts` ( >> `id` int(6) NOT NULL auto_increment, .. ^^^^^^ >> `first` varchar(15) NOT NULL, >> `last` varchar(15) NOT NULL, >> `phone` varchar(20) default NULL, >> `mobile` varchar(20) default NULL, >> `fax` varchar(20) default NULL, >> `email` varchar(30) default NULL, >> `web` varchar(30) default NULL, >> PRIMARY KEY (`id`), >> UNIQUE KEY `id` (`id`), >> UNIQUE KEY `last_name` (`last`), >> KEY `id_2` (`id`) >> ) ENGINE=InnoDB DEFAULT CHARSET=latin1; >> >> insert into table contacts values '','steve','cristaldi','','','','',''); >> >> >> You have an error in your SQL syntax; check the manual that corresponds >> to your MySQL server version for the right syntax to use near 'table >> contacts values ('','steve','kurowski','','','','','')' at line 1 A) you'll not be inserting '' into an int(6) column any time soon. B) which means you'll probably want to enumerate the columns you ARE filling: insert into contacts ( first, last, phone, mobile fax, web ) values ('steve', 'cristaldi', '', '', '', '' ); C) you're allowing the other columns to be null... why not let them be null instead of blank? As in: insert into contacts ( first, last, ) values ( 'steve', 'cristaldi' ); D) I am not sure about the UNIQUE on the last name. What happens when you have Joe Smith and Bill Smith? (I'm honestly unsure about this one; I haven't played with this option by hand.) -- This was, apparently, beyond her ken. So far beyond her ken that she was well into barbie territory. -- J. D. Baldwin |