locked
sql to set allow null RRS feed

  • Question

  • can u help me 

    I need sql query to set allow null propery of a colum ( true /false)

    hw to do it 


    bahushekh
    Monday, January 31, 2011 8:19 AM

Answers

  • To allow NULL use the below

    --exist column

    ALTER TABLE tbl ALTER COLUMN col INT NULL

    --New column

    ALTER TABLE tbl ADD col INT NULL

     


    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/
    • Proposed as answer by Muhammad Abbas Monday, January 31, 2011 12:23 PM
    • Marked as answer by bahushekh Monday, January 31, 2011 4:52 PM
    Monday, January 31, 2011 9:57 AM
    Answerer

All replies

  • Hi,

    You can use alter statement

     

    alter table tablename alter column columnname datatype null

     

    However there are various considerations while changing the column to accept NOT NULL value!!!


    Thanks and regards, Rishabh
    Monday, January 31, 2011 8:36 AM
  • You can use the following sql statment

    ALTER TABLE tablename ALTER COLUMN columnname VARCHAR(50) NOT NULL
    
    

    Thanks,
    A.m.a.L
    [MVP Visual C#]
    Dot Net Goodies
    Don't hate the hacker, hate the code
    Monday, January 31, 2011 8:36 AM
  • go through the below link for more detail on modifying a table structure or column structure:

    http://msdn.microsoft.com/en-us/library/ms190273.aspx

     


    --------------------------------- Devender Bijania
    Monday, January 31, 2011 9:27 AM
  • To allow NULL use the below

    --exist column

    ALTER TABLE tbl ALTER COLUMN col INT NULL

    --New column

    ALTER TABLE tbl ADD col INT NULL

     


    Best Regards, Uri Dimant SQL Server MVP http://dimantdatabasesolutions.blogspot.com/ http://sqlblog.com/blogs/uri_dimant/
    • Proposed as answer by Muhammad Abbas Monday, January 31, 2011 12:23 PM
    • Marked as answer by bahushekh Monday, January 31, 2011 4:52 PM
    Monday, January 31, 2011 9:57 AM
    Answerer