This will be a little brute force method, but you can always find all the columns of the datetime data type using the sys.columns , grab the table name and column name, sys.columns over the list with the cursor, and create an ALTER TABLE statement for each record as follows:
ALTER TABLE @tablename ALTER COLUMN @columnname datetime2
Then run the specified statement using EXEC . Obviously, you need to have permissions for both the sys.columns query and the ALTER all these tables ...
Sorry that there is not much code in this answer - there is no copy of SSMS on this computer and cannot remember the syntax for all of this from memory. :)
Dan J Sep 05 '10 at 1:50 2010-09-05 01:50
source share