Created
March 31, 2014 12:13
-
-
Save Godoy/9890991 to your computer and use it in GitHub Desktop.
script sql para alterar a collation de todas as colunas no banco de dados sql server - salvar como txt e rodar os scripts.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare @NewCollationName sysname | |
set @NewCollationName = 'SQL_Latin1_General_CP1_CI_AI' | |
select | |
'ALTER TABLE ' + QUOTENAME(SCHEMA_NAME(st.schema_id)) + '.' + QUOTENAME(st.name) + | |
' ALTER COLUMN ' + QUOTENAME(sc.name) + ' ' + styp.name + '(' + | |
CASE WHEN sc.max_length = -1 THEN 'max' ELSE CONVERT(varchar(10),sc.max_length) END + | |
') collate ' + @NewCollationName + ' | |
go | |
' | |
from | |
sys.columns sc | |
inner join | |
sys.tables st | |
on | |
sc.object_id = st.object_id | |
inner join | |
sys.types styp | |
on | |
sc.user_type_id = styp.user_type_id | |
where | |
sc.collation_name is not null and | |
OBJECTPROPERTY(st.object_id,N'IsMSShipped')=0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment