On Sun, 2001-11-04 at 13:52, Chris Williams wrote:
> I'm trying to create at table that inserts a default value into a field if
> nothing is supplied. If in interpret the documentation correctly this should
> be accomplished by something like this:
> 
> CREATE TABLE Location (LocationID VARCHAR(10) NOT NULL PRIMARY KEY, Name
> VARCHAR(50),  Address1 VARCHAR(50), Address2 VARCHAR(50), City VARCHAR(50),
> State VARCHAR(50), Zip VARCHAR(10), Phone VARCHAR(20), Email VARCHAR(50),
> URL VARCHAR(75) , Icon INT DEFAULT 1)
> 
> Where the Icon field will get set to 1 if no value is supplied upon insert.
> 
> When I insert a row such as:
> INSERT INTO LocationTEMP VALUES (100,1,2,3,4,5,6,7,8,9,'')
> 
> zero (0) gets inserted in the Icon field.
> 
> It appears DEFAULT doesn't work.
> 

No, you're telling it to insert a value -- namely, '', which becomes a
0.  Try NULL instead, or better, try a query that doesn't set that value
at all, like:

INSERT INTO Location (LocationID, Name, Address1, Address2, City, State,
Zip, Phone, Email, URL) VALUES (100, 1, 2, 3, 4, 5, 6, 7, 8, 9)

Steve Meyers


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