"Update All tables COLLATE DATABASE_DEFAULT" Code Answer's

You're definitely familiar with the best coding language SQL that developers use to develop their projects and they get all their queries like "Update All tables COLLATE DATABASE_DEFAULT" answered properly. Developers are finding an appropriate answer about Update All tables COLLATE DATABASE_DEFAULT related to the SQL coding language. By visiting this online portal developers get answers concerning SQL codes question like Update All tables COLLATE DATABASE_DEFAULT. Enter your desired code related query in the search bar and get every piece of information about SQL code related question on Update All tables COLLATE DATABASE_DEFAULT. 

Update All tables COLLATE DATABASE_DEFAULT

By Selfish ShrikeSelfish Shrike on May 26, 2021
DECLARE @collate nvarchar(100);
DECLARE @table nvarchar(255);
DECLARE @column_name nvarchar(255);
DECLARE @column_id int;
DECLARE @data_type nvarchar(255);
DECLARE @max_length int;
DECLARE @row_id int;
DECLARE @sql nvarchar(max);
DECLARE @sql_column nvarchar(max);

SET @collate = 'Latin1_General_CI_AS';

DECLARE local_table_cursor CURSOR FOR

SELECT [name]
FROM sysobjects
WHERE OBJECTPROPERTY(id, N'IsUserTable') = 1

OPEN local_table_cursor
FETCH NEXT FROM local_table_cursor
INTO @table

WHILE @@FETCH_STATUS = 0
BEGIN

    DECLARE local_change_cursor CURSOR FOR

    SELECT ROW_NUMBER() OVER (ORDER BY c.column_id) AS row_id
        , c.name column_name
        , t.Name data_type
        , c.max_length
        , c.column_id
    FROM sys.columns c
    JOIN sys.types t ON c.system_type_id = t.system_type_id
    LEFT OUTER JOIN sys.index_columns ic ON ic.object_id = c.object_id AND ic.column_id = c.column_id
    LEFT OUTER JOIN sys.indexes i ON ic.object_id = i.object_id AND ic.index_id = i.index_id
    WHERE c.object_id = OBJECT_ID(@table)
    ORDER BY c.column_id

    OPEN local_change_cursor
    FETCH NEXT FROM local_change_cursor
    INTO @row_id, @column_name, @data_type, @max_length, @column_id

    WHILE @@FETCH_STATUS = 0
    BEGIN

        IF (@max_length = -1) OR (@max_length > 4000) SET @max_length = 4000;

        IF (@data_type LIKE '%char%')
        BEGIN TRY
            SET @sql = 'ALTER TABLE ' + @table + ' ALTER COLUMN ' + @column_name + ' ' + @data_type + '(' + CAST(@max_length AS nvarchar(100)) + ') COLLATE ' + @collate
            PRINT @sql
            EXEC sp_executesql @sql
        END TRY
        BEGIN CATCH
          PRINT 'ERROR: Some index or constraint rely on the column' + @column_name + '. No conversion possible.'
          PRINT @sql
        END CATCH

        FETCH NEXT FROM local_change_cursor
        INTO @row_id, @column_name, @data_type, @max_length, @column_id

    END

    CLOSE local_change_cursor
    DEALLOCATE local_change_cursor

    FETCH NEXT FROM local_table_cursor
    INTO @table

END

CLOSE local_table_cursor
DEALLOCATE local_table_cursor

GO

Source: stackoverflow.com

Add Comment

0

All those coders who are working on the SQL based application and are stuck on Update All tables COLLATE DATABASE_DEFAULT can get a collection of related answers to their query. Programmers need to enter their query on Update All tables COLLATE DATABASE_DEFAULT related to SQL code and they'll get their ambiguities clear immediately. On our webpage, there are tutorials about Update All tables COLLATE DATABASE_DEFAULT for the programmers working on SQL code while coding their module. Coders are also allowed to rectify already present answers of Update All tables COLLATE DATABASE_DEFAULT while working on the SQL language code. Developers can add up suggestions if they deem fit any other answer relating to "Update All tables COLLATE DATABASE_DEFAULT". Visit this developer's friendly online web community, CodeProZone, and get your queries like Update All tables COLLATE DATABASE_DEFAULT resolved professionally and stay updated to the latest SQL updates. 

SQL answers related to "Update All tables COLLATE DATABASE_DEFAULT"

View All SQL queries

SQL queries related to "Update All tables COLLATE DATABASE_DEFAULT"

Update All tables COLLATE DATABASE_DEFAULT update all linkedserver tables with openquery on db show size of all tables postgres find a column in all tables postgres drop all tables db2 get all tables with column name sql delete all tables from database mysql drop all tables in azure sql database stored procedure to change name of column for all dependent tables and views Sql drop all tables You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column. set utf8mb4 mysql tables select tables with name like mysql could not find driver (SQL: select * from information_schema.tables where table_schema = pics and table_name = migrations and table_type = 'BASE TABLE') sql show tables mysql dump specific tables get tables in database sql list mysql tables and views C# mysql data reader from two tables how to check tables without schema in sql oracle sql union tables with different columns create tables from xsd to sql server database c# checking tables without schema in sql server dump multiple tables mysql sql get list of domains and the tables that use them sql select column name like from multiple tables how to make sure two tables have same exact data in sql Database owner can't create new tables postgres oracle list partitioned tables sql transact create cursor with dynamic tables oracle sql select from multiple tables sql combine results from two tables how to check tables in mysql how to format tables in sqlplus show database not empty tables postgres enlever les doubles espaces dans les tables postgresql select from 3 tables one is empty mysql drop tables how to get the elements that missing in other tables sql Postgres show tables update with inner join sql update query update left join mysql sql server update c# example code pl sql trigger determine if insert or update or delete update part of a string in mysql postgresql update sequence next value how to update an attribute in MySQL update substring in mysql update mysql mysql update query sql oracle update multiple rows update column data type postgres update with inner join postgres sql update from select update a row in sql mysql select update same table t-sql update from select update from select join update using case in mysql how to update data in sql UPDATE command in SQL grant update privilege command in mysql update from select oracle C# mysql update statement set value to null automatically update database last seen datetime in sql mysql update sequence with order by update sql sintassi update query with between in mysql deny select insert update delete sql update database collation in postgresql postegresql update to null update and keep original value sql sql server update column based on another table sql update with field from another table mysql update value how to update sql server version update multiple columns in mysql update/delet in mssql oracle c# multiple update sql update sqlaclehmy sqlalchemy.orm.evaluator.UnevaluatableError: Cannot evaluate BinaryExpression with operator How to update field to subtract value to existing value if that value is lesser than the existing value balance value should be subtract from the next coloumn in MySQL update from select update a table with values from another table Check if value exisits update or insert sQL update query for multiple columns update from select postgresql list all permissions on a table in postgres how to show all users in mysql show all users in mysql sql print all names that start with a given letter influxdb list all tags for a measurement plsql check how much space all databases are consuming how to list all values of a column that start with a letter in sql how to set all the min and sec data to zero in sql server get all employees if name ends with in sql ms sql filter all sympbol mql5 list all available symbols selects all the columns from the sailors table mysql select all columns and specific fields as remove all spaces from string sql select all domains of database firbird sql statement show all emails with dome delete all records from table check all indexes on table postgres kill all connections delete all duplicate rows keep the latest except for one in mysql

Browse Other Code Languages

CodeProZone