SQL syntax

  • I created a small table with multiple columns. I intended to make one of the columns "not null". I would like to use the alter table command to make that change but I can't seem to find the correct syntax. Here is what I've tried:

    alter table tablename alter column columnname not null;

    SQL complains that it doesn't understand 'not null' with this syntax. I've tried enclosing it in quotes, parenthesis, square brackets, but it likes none of those.

    Any suggestions would be greatly appreciated.

  • You need to include the data type before the not null.

    Alter table dbo.table

    Alter Column column_name Int Not Null

  • Thanks, such a simple answer. I have a real problem finding good examples of such things either on the internet or in the SQL books online.

  • Rodney

    You can open your table in enterprize manager, make your changes, but instead of hitting the save button, there is another button that looks like a scroll, that will show you the script for the changes you just made.

    Greg
    _________________________________________________________________________________________________
    The glass is at one half capacity: nothing more, nothing less.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply