Hi Rick,

You absolutely right, you are not required to specify field names in an
Insert.  But it's a good idea to do so.  1) It makes you code more readable
for those following you.  2) If your table ever changes structure, your
Insert will still work. (Assuming you didn't remove one or more of the
fields you are inserting into.)

Cal
http://www.calevans.com


-----Original Message-----
From: Rick Emery [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, March 27, 2001 1:25 PM
To: [EMAIL PROTECTED]
Subject: RE: help on mysql tables


You DO NOT need to specify table field names when INSERTing records.  For
instance, if the table were defined thus:

CREATE TABLE mytable (
  valueA varchar(10) NOT NULL,
  valueB varchar(25),
  valueC varchar(30) );

This statement will insert one record:
  INSERT INTO mytable VALUES("some text", "more text", "last text");

To insert multiple records, go with:
  INSERT INTO mytable VALUES("some text", "more text", "last text"),("record
2","text for 2","last text in 2");
----- Original Message -----
From: "Ramasamy Palaniappan" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, March 27, 2001 6:53 AM
Subject: help on mysql tables


> I have created the following table:
>
> create table test(name varchar(10) NOT NULL);
> query is ok

Yes, but notice that you put a constraint of NOT NULL on the field. This
means that there has to be a value in this field, in every record.

> I HAVE TRIED THE FOLLOWING QUERY :
>
> insert into test values("");
>
> MYSQL COMMAND IS ACCEPTING THE ABOVE QUERY WHICH VIOLATES NOT NULL
> CONSTRAINTS.

First problem is that you should specify a table field after the table name
and you should specify a corresponding piece of data in the VALUES portion
of your statement. Next, you need to make sure that the data you enter is
NOT blank since the field has a NOT NULL constraint. Finally, you should
encase your data in single quotation marks, not double quotation marks.
Therefore, change your statement to:

INSERT INTO test(name) VALUES('something');

If your table has only one field, you can also use the statement below:

INSERT INTO test VALUES('something');

Good luck,

Dennis
**********************************************'
Beridney Computer Services
[EMAIL PROTECTED]
P: 703-566-3196
http://www.beridney.com



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php



---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to