Re: Setting a DEFAULT value

2001-11-04 Thread Steve Meyers

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




RE: Setting a DEFAULT value

2001-11-04 Thread Chris Book

I suggest a few things.  First, set it to NOT NULL DEFAULT 1, and then set
the value explicitly to null, which will cause it to use the default value.
The problem with inserting '' is that its casting to an integer and mysql
decides that '' should be 0.  Or try using : insert into table (column1,
column2, etc) value (value1, value2, etc) but don't include icon in your
list of columns and that will default it to 1.

Chris

-Original Message-
From: Chris Williams [mailto:[EMAIL PROTECTED]]
Sent: Sunday, November 04, 2001 3:52 PM
To: [EMAIL PROTECTED]
Subject: Setting a DEFAULT value


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.

Thanks,
Chris Williams


-
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