Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a not null to an already existing column in SQL Server? [duplicate]

I've setup a table in SQL Server 2008 Express and forgot to add a not null constraint to my unique recordid column. I tried to add it afterward, with this statement:

alter table movie_archive alter column RecordID Not null;

but it gives me an error message, saying there's a syntax error at "not". What am I doing wrong?

like image 822
kyle5385 Avatar asked Jul 07 '13 17:07

kyle5385


People also ask

Can we add a NOT NULL column to an existing table?

You can add a not null column at the time of table creation or you can use it for an existing table. In the above table, we have declared Id as int type that does not take NULL value. If you insert NULL value, you will get an error.


1 Answers

specify the datatype of the column

ALTER TABLE [Table] ALTER COLUMN [Column] INTEGER NOT NULL;

alter table movie_archive alter column RecordID INTEGER Not null;
like image 140
chetan Avatar answered Oct 23 '22 11:10

chetan