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

Posted on 2009-04-21
Last Modified: 2012-05-06
Because of some historic reasons I want to be able to modify a column like:
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')


Open in new window

Question by:midfde
    LVL 142

    Accepted Solution

    you do have to specify the data type, you cannot change to NULL/NOT NULL without .
    LVL 31

    Assisted Solution

    yes, there is not way to do so

    Featured Post

    Find Ransomware Secrets With All-Source Analysis

    Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

    Join & Write a Comment

    Suggested Solutions

    Nowadays, some of developer are too much worried about data. Who is using data, who is updating it etc. etc. Because, data is more costlier in term of money and information. So security of data is focusing concern in days. Lets' understand the Au…
    Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now