Question : To change asni_padding setting of a column.

SQL Server 2005

How to change asni_padding setting of a column without recreating the entire table.

Here is the ansi_padding setting of columns of table bank.

table_name      column_name      ansi_padding_setting
bank      bank_code      0
bank      bank_name      0
bank      branch_name      0
bank      abbr      1
bank      address      1

I want to set ansi_padding off to columns bank_abbr, bank_address.

Answer : To change asni_padding setting of a column.

An ALTER COLUMN is nog going to work. As the BOL states: "•ANSI_PADDING padding is always ON for ALTER COLUMN" (See http://msdn.microsoft.com/en-US/library/ms190273(v=SQL.90).aspx).

So th only way I can think of without recreating the whole table is:
- adding a new column
- copying the data from the old column
- dropping the old column
- renaming the new column

I think recreating the table is faster.
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
SET ANSI_PADDING OFF
GO
ALTER TABLE bank ADD abbr_tmp VARCHAR(50) NOT NULL
GO
UPDATE bank SET abbr_tmp = abbr
GO
ALTER TABLE bank DROP COLUMN abbr
GO
EXEC sp_rename 'dbo.bank.abbr_tmp', 'abbr', 'COLUMN'
GO
Random Solutions  
 
programming4us programming4us