sql server 2005 - Change primary key to a nullable column without losing data -
i have table in have data.
i have primary key on column, want change column rencently added. added column nullable, updated able make not null.
i used
alter table mytable modify termdefid int not null
but receive error
incorrect syntax near 'modify'.
after want (after drop current pk, of course) :
alter table [dbo].[mytable] add constraint [pk_mytable] primary key clustered ( [termdefid] asc )with (pad_index = off, statistics_norecompute = off, sort_in_tempdb = off, ignore_dup_key = off, online = off, allow_row_locks = on, allow_page_locks = on, fillfactor = 90) on [primary] go
i not able make new column not null
. problem. how can this?
i use sql server 2005, maybe problem!
in sql server, primary key column(s) cannot nullable
also: alter table
command invalid sql server - should be:
alter table mytable alter column termdefid int not null
but again: if column part of primary key, it cannot nullable.
see relevant msdn documentation on primary key constraints:
a table can have 1 primary key constraint, , a column participates in primary key constraint cannot accept null values. because primary key constraints guarantee unique data, defined on identity column.
Comments
Post a Comment