Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 ALTER TABLE

Author  Topic 

dcarva
Posting Yak Master

140 Posts

Posted - 2005-08-12 : 15:04:36
Hello,

I have a table that has a "MachineStatus" column. This column is set to allow nulls. But when the customer upgrades to our new application, I need to set any NULL values in that column to '' and then change the column to NULL. How can I do this? I can't drop and re-create the column because it would delete the data. I looked at AlTER TABLE. I just need to remove the ALLOW NULL setting.

Thanks!
Danny

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2005-08-12 : 15:06:15
UPDATE YourTable SET MachineStatus = '' WHERE MachineStatus IS NULL
GO
ALTER TABLE YourTable ALTER COLUMN MachineStatus varchar(nn) NOT NULL
GO

Tara
Go to Top of Page

paulrandal
Yak with Vast SQL Skills

899 Posts

Posted - 2005-08-12 : 15:07:37
For example:

UPDATE MyTable SET MachineStatus = N'NULL' WHERE MachineStatus IS NULL
ALTER TABLE MyTable ALTER COLUMN MachineStatus NVARCHAR(20) NOT NULL


Paul Randal
Dev Lead, Microsoft SQL Server Storage Engine
(Legalese: This posting is provided "AS IS" with no warranties, and confers no rights.)
Go to Top of Page

dcarva
Posting Yak Master

140 Posts

Posted - 2005-08-12 : 15:08:18
ALTER COLUMN - Awesome! I overlooked it.
Go to Top of Page
   

- Advertisement -