Convert a column from a date to a Datetime Sql server

I have a column with a name Lastmodifiedwith a data type Date, but it should be DateTime.

Is there a way to convert a column?

When I use the Design function of SQL Server Management Studio, I get the following error:

Saving changes is not allowed. The changes you made require the following table to be deleted and recreated.

I am not very interested in displaying a table, I just want to know if it is possible to convert a column from Dateto DateTimeor if I need to delete a column and create a new one with the correct data type

+5
source share
3 answers

, .

SQL:

ALTER TABLE Tab ALTER COLUMN LastModified datetime2 not null

( datetime2 datetime, , date, , SQL Server 2008 )

+20

SQL Server Mgmt Studio - , : -)

enter image description here

, , !

+2

. , .

SQL Management Studio , , , , . , .

, , SQL script , , , sp_rename, . , SQL Management Studio, , , .

However, if you want to allow SQL Manangement Studio to do this this way, you can disable this error message. I believe this was originally added because, by default, people did not want and did not recreate the table. To disable this message, open “Tools-> Options-” Designers and uncheck the box “Prevent save changes that require re-creating the table” , then you can save your changes in the designer.

Prevent saving changes that require table re-creation

+2
source

All Articles