I have an SQL Server 2008 database with many tables. I\'ve been using the now lame datetime
datatype and want to use the new and better datetime2
.
This would be a bit of a brute-force method, but you could always look up all columns of datatype datetime
using the sys.columns
view, grab the table name and column name, iterate over that list with a cursor, and for each entry generate an ALTER TABLE statement like so:
ALTER TABLE @tablename ALTER COLUMN @columnname datetime2
Then run said statement with EXEC
. Obviously, you'd need to have permissions both to query sys.columns
and to ALTER
all of those tables...
Apologies there isn't more code in this answer - don't have a copy of SSMS on this machine, and can't remember the syntax for all of that from memory. :)