SQL_Database ve Table Collation name değiştirme ( Alter Collation Name)

Blog Detay

SQL_Database ve Table Collation name değiştirme ( Alter Collation Name)

SQL_Database ve Table Collation name değiştirme ( Alter Collation Name)

<p>ALTER DATABASE SManagement SET SINGLE_USER WITH ROLLBACK IMMEDIATE<br /> ALTER DATABASE SManagement COLLATE SQL_Latin1_General_CP1_CI_AS<br /> ALTER DATABASE SManagement SET MULTI_USER</p> <p>&nbsp;</p> <p>&nbsp;</p> <blockquote> <p>DECLARE @collate nvarchar(100);<br /> DECLARE @table nvarchar(255);<br /> DECLARE @column_name nvarchar(255);<br /> DECLARE @column_id int;<br /> DECLARE @data_type nvarchar(255);<br /> DECLARE @max_length int;<br /> DECLARE @row_id int;<br /> DECLARE @sql nvarchar(max);<br /> DECLARE @sql_column nvarchar(max);</p> <p>SET @collate = &#39;SQL_Latin1_General_CP1_CI_AS&#39;;</p> <p>DECLARE local_table_cursor CURSOR FOR</p> <p>SELECT [name]<br /> FROM sysobjects<br /> WHERE OBJECTPROPERTY(id, N&#39;IsUserTable&#39;) = 1</p> <p>OPEN local_table_cursor<br /> FETCH NEXT FROM local_table_cursor<br /> INTO @table</p> <p>WHILE @@FETCH_STATUS = 0<br /> BEGIN</p> <p>&nbsp; &nbsp; DECLARE local_change_cursor CURSOR FOR</p> <p>&nbsp; &nbsp; SELECT ROW_NUMBER() OVER (ORDER BY c.column_id) AS row_id<br /> &nbsp; &nbsp; &nbsp; &nbsp; , c.name column_name<br /> &nbsp; &nbsp; &nbsp; &nbsp; , t.Name data_type<br /> &nbsp; &nbsp; &nbsp; &nbsp; , c.max_length<br /> &nbsp; &nbsp; &nbsp; &nbsp; , c.column_id<br /> &nbsp; &nbsp; FROM sys.columns c<br /> &nbsp; &nbsp; JOIN sys.types t ON c.system_type_id = t.system_type_id<br /> &nbsp; &nbsp; LEFT OUTER JOIN sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id<br /> &nbsp; &nbsp; LEFT OUTER JOIN sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id<br /> &nbsp; &nbsp; WHERE c.object_id = OBJECT_ID(@table)<br /> &nbsp; &nbsp; ORDER BY c.column_id</p> <p>&nbsp; &nbsp; OPEN local_change_cursor<br /> &nbsp; &nbsp; FETCH NEXT FROM local_change_cursor<br /> &nbsp; &nbsp; INTO @row_id, @column_name, @data_type, @max_length, @column_id</p> <p>&nbsp; &nbsp; WHILE @@FETCH_STATUS = 0<br /> &nbsp; &nbsp; BEGIN</p> <p>&nbsp; &nbsp; &nbsp; &nbsp; IF (@max_length = -1) OR (@max_length &gt; 4000) SET @max_length = 4000;</p> <p>&nbsp; &nbsp; &nbsp; &nbsp; IF (@data_type LIKE &#39;%char%&#39;)<br /> &nbsp; &nbsp; &nbsp; &nbsp; BEGIN TRY<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SET @sql = &#39;ALTER TABLE &#39; + @table + &#39; ALTER COLUMN &#39; + @column_name + &#39; &#39; + @data_type + &#39;(&#39; + CAST(@max_length AS nvarchar(100)) + &#39;) COLLATE &#39; + @collate<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINT @sql<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; EXEC sp_executesql @sql<br /> &nbsp; &nbsp; &nbsp; &nbsp; END TRY<br /> &nbsp; &nbsp; &nbsp; &nbsp; BEGIN CATCH<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINT &#39;ERROR: Some index or constraint rely on the column&#39; + @column_name + &#39;. No conversion possible.&#39;<br /> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PRINT @sql<br /> &nbsp; &nbsp; &nbsp; &nbsp; END CATCH</p> <p>&nbsp; &nbsp; &nbsp; &nbsp; FETCH NEXT FROM local_change_cursor<br /> &nbsp; &nbsp; &nbsp; &nbsp; INTO @row_id, @column_name, @data_type, @max_length, @column_id</p> <p>&nbsp; &nbsp; END</p> <p>&nbsp; &nbsp; CLOSE local_change_cursor<br /> &nbsp; &nbsp; DEALLOCATE local_change_cursor</p> <p>&nbsp; &nbsp; FETCH NEXT FROM local_table_cursor<br /> &nbsp; &nbsp; INTO @table</p> <p>END</p> <p>CLOSE local_table_cursor<br /> DEALLOCATE local_table_cursor</p> <p>GO</p> </blockquote>

Bunu paylaş
Sql Veritabanı Tüm Tablo,Kolon ve İçeriklerde Arama Yapmak
SQLINFO_Son tarihe göre filtreleme_SUBSTR_Logo
Yazar erydogan
1992 yılı İstanbul doğumluyum. "Beykent Üniversitesi/Bilgisayar Programcılığı" bölümü mezunuyum, 7 yılı aşkın süredir Logo firmasının üretmiş olduğu ERP ürünlerine teknik destek vermek üzere “Logo Erp Danışmanı/Sistem Uzmanı” olarak çalıştım. 2020 Şubat ayında yıllardır hayalini kurduğum "kendi işimi yapma" düşüncemi hayata geçirmek üzere DGN Yazılım firmasını kurdum. Ayrıca .Net C# (MVC) yazılım dilini kullanarak Web tabanlı/Mobil Uyumlu, Logo yazılım entegreli ya da tamamen bağımsız uygulamalar geliştiriyorum.

İlişkili Bloglar:

0 Yorum

Copyrights © 2020 All Rights Reserved by DGN Software.