Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How can I update a tinyint value to be NULL?

Status
Not open for further replies.

XgrinderX

Programmer
Mar 27, 2001
225
US
I am trying to update a value in my table. I have a field called tiPhone and it is a tinyint. I want to be able to update it to NULL but when I try to do it, instead it updates to 0.

UPDATE tblUser SET tiPhone = 'NULL' WHERE iUserID = 1

The above query will set the tiPhone value to 0 every time, but I want it to be NULL. How can I accomplish this?

-Greg
 
Jeesh.

Nevermind, I figured it out. It wanted NULL without the single quotes. For integer field it wants the quotes but apparently for tinyint it does not.
 
for integer field it wants the quotes" is not correct

you should never use quotes around numeric literals

:)

r937.com | rudy.ca
 
if i don't it gives an error. my first attempt was with no quotes on any of them. then i tried with the single quotes on all of them. after some trial and error, i landed on this.

unless you know something i don't know - it's working fine now with the 'NULL' for ints and just NULL for tinyints. not sure why it works that way, but it does.
 
Pulled this out of the table properties in Navicat. Hope it has what you need. Does it really matter as long as it works for me?

CREATE TABLE `tbluser` (
`iUserID` int(11) NOT NULL auto_increment,
`iGroupID` int(11) default NULL,
`sUserName` varchar(16) default NULL,
`sPassword` varchar(16) default NULL,
`sFirstName1` varchar(50) default NULL,
`sLastName1` varchar(50) default NULL,
`sFirstName2` varchar(50) default NULL,
`sLastName2` varchar(50) default NULL,
`sAddress1` varchar(150) default NULL,
`sAddress2` varchar(150) default NULL,
`sCity` varchar(100) default NULL,
`sState` char(2) default NULL,
`sZip` varchar(10) default NULL,
`sEmail1` varchar(100) default NULL,
`tiEmail1` tinyint(4) default NULL,
`sEmail2` varchar(100) default NULL,
`tiEmail2` tinyint(4) default NULL,
`sEmail3` varchar(100) default NULL,
`tiEmail3` tinyint(4) default NULL,
`sEmail4` varchar(100) default NULL,
`tiEmail4` tinyint(4) default NULL,
`sPhone1` varchar(12) default NULL,
`iPhone1ID` int(11) default NULL,
`tiPhone1` tinyint(4) default NULL,
`sPhone2` varchar(12) default NULL,
`iPhone2ID` int(11) default NULL,
`tiPhone2` tinyint(4) default NULL,
`sPhone3` varchar(12) default NULL,
`iPhone3ID` int(11) default NULL,
`tiPhone3` tinyint(4) default NULL,
`sPhone4` varchar(12) default NULL,
`iPhone4ID` int(11) default NULL,
`tiPhone4` tinyint(4) default NULL,
`sPhone5` varchar(12) default NULL,
`iPhone5ID` int(11) default NULL,
`tiPhone5` tinyint(4) default NULL,
`nSSN1` int(11) default NULL,
`nSSN2` int(11) default NULL,
`dtJoinDate` datetime default NULL,
`dtLastLogin` datetime default NULL,
`sWebMailUser` varchar(15) default NULL,
`sWebMailPass` varchar(15) default NULL,
`sUserNotes` varchar(250) default NULL,
PRIMARY KEY (`iUserID`),
KEY `sUserName` (`sUserName`)
) TYPE=InnoDB COMMENT='InnoDB free: 4096 kB; InnoDB free: 4096 kB; InnoDB free: 409'
 
when you insert a character string like 'fred' or 'NULL' (both of which are not valid integers) into an integer column that has been defined as default NULL, then you will get the default

it's as simple as that :)

does it really matter? well, i think it does -- you will have nothing but frustration if you ever use another database besides mysql, which is very "forgiving" (to put it kindly)

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top