Unix Technical Forum

insert problem....

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) ...


Go Back   Unix Technical Forum > Database Server Software > MySQL

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-28-2008, 09:13 AM
someone
 
Posts: n/a
Default insert problem....

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 02-28-2008, 09:13 AM
someone
 
Posts: n/a
Default Re: insert problem....

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-28-2008, 09:13 AM
Chris ( Val )
 
Posts: n/a
Default Re: insert problem....


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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-28-2008, 09:13 AM
Jerry Stuckle
 
Posts: n/a
Default Re: insert problem....

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
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-28-2008, 09:13 AM
Jerry Stuckle
 
Posts: n/a
Default Re: insert problem....

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
==================
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6 (permalink)  
Old 02-28-2008, 09:13 AM
Peter H. Coffin
 
Posts: n/a
Default Re: insert problem....

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 05:09 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com