Skip to content

Instantly share code, notes, and snippets.

@Godoy
Created March 31, 2014 12:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Godoy/9890991 to your computer and use it in GitHub Desktop.
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.
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