Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2398
  • Last Modified:

How do I change a table column from NULL to NOT NULL by T-SQL

Because of some historic reasons I want to be able to modify a column like:
ALTER TABLE [t] ALTER COLUMN [c] NOT NULL
Transact SQL does not allow this syntax: I think it wants data type after the column name.
Is there a way to say "Change this column to NOT NULL whatever type it is"?
Could you please help me to complete a store procedure (See code) without inquiring INFORMATION_SCHEMA?

PS: Example.
alter table [Anomaly Entries] alter column [anomalyID] varchar(15) not null -- works
alter table [Anomaly Entries] alter column [anomalyID]                    not null -- does not

create proc change_to_not_null(@tn as sysname, @cn as sysname)as 
exec ('alter table [' + @tn + ']alter column ' + @cn +<???> + ' NOT NULL')
go

Open in new window

0
midfde
Asked:
midfde
2 Solutions
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you do have to specify the data type, you cannot change to NULL/NOT NULL without .
0
 
RiteshShahCommented:
yes, there is not way to do so
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now