将datetime更改为日期数据类型?

时间:2021-06-12 16:31:49

I have a column BirthDate in a table that is using the datetime data type. Currently, the values resemble the format 1987-12-30 00:00:00.000.

我在使用datetime数据类型的表中有一个列BirthDate。目前的值类似于1987-12-30 00:00.000格式。

I would like to update all the rows of this table, changing them to the following format with the date data type: 1987-12-30

我想更新这个表的所有行,将它们更改为以下格式,使用日期数据类型:1987-12-30

I can run a SELECT...

我可以选择…

SELECT CONVERT(date, BirthDate) FROM CUSTOMERLIST

But this is only affecting the display. I would like for it to update the entire column and also change the data type of that attribute as well. Any assistance would be greatly appreciated!

但这只会影响显示器。我希望它能够更新整个列,并更改该属性的数据类型。如有任何帮助,我们将不胜感激!

1 个解决方案

#1


24  

You will need to ALTER the table:

您需要更改表:

ALTER TABLE CUSTOMERLIST ALTER COLUMN BirthDate date not null

See Sql Fiddle with demo

参见Sql小提琴演示

#1


24  

You will need to ALTER the table:

您需要更改表:

ALTER TABLE CUSTOMERLIST ALTER COLUMN BirthDate date not null

See Sql Fiddle with demo

参见Sql小提琴演示