Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does SQL Server force me to drop the table to be able to alter a field from DateTime to DateTime2(3)?

I am trying to alter a table field - with some rows in it - from DateTime to DateTime2(3).

But the SQL Server Management Studio complains that I have drop and re-create the table.

But why?

Isn't DateTime2(3) has more precision than DateTime type? It should be fine, should not it be?

like image 314
pencilCake Avatar asked Dec 29 '11 14:12

pencilCake


1 Answers

There is a setting in SSMS that will allow you to do what you want.. Menu-Tools-Options-Designers-Prevent saving changes that require table re-creaction.

SSMS has a habit of recreating almost any changes you do. It should be just fine to only alter the column data type with something like this.

alter table TableName alter column ColName datetime2(3)
like image 167
Mikael Eriksson Avatar answered Oct 03 '22 09:10

Mikael Eriksson