sql - 在特定列上设置 ANSI_PADDING(同一表的不同列中 ANSI_PADDING ON 和 OFF)

标签 sql sql-server ddl

是否可以 - 使用单个 CREATE TABLE 脚本 - 将特定的 varbinaryANSI_PADDING = ON 设置为 ANSI_PADDING = ON,而将其他列设置为 ANSI_PADDING = OFF

例如

CREATE TABLE PaddingX (
    ...
    ColumnA varbinary(max),
    ...    
    ColumnB varbinary(50)
)

我希望 ColumnA 进行修剪(填充 OFF),但 ColumnB 包含完整(填充的)值 - 填充

最佳答案

您必须分两步完成:

SET ANSI_PADDING OFF
-- create the table without the columns that need ANSI padding
SET ANSI_PADDING ON
-- alter the table to add the columns that need ANSI padding

这是唯一的方法。

如果你看SET ANSI_PADDING docs的言论,您可以阅读:

This setting affects only the definition of new columns. After the column is created, SQL Server stores the values based on the setting when the column was created. Existing columns are not affected by a later change to this setting.

注意:要添加新列,您可以查看 ALTER TABLE docs 的示例.

关于sql - 在特定列上设置 ANSI_PADDING(同一表的不同列中 ANSI_PADDING ON 和 OFF),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28668954/

相关文章:

sql - 键不在表中

sql - 如何进行 SQL 查询以从表中获取某些特定范围的行

mysql - 如果在另一个表上匹配,则排除一个表中的行 - MySql

sql - 微软 Access : setting table column Caption or Description in DDL?

Mysql->与另一个字段相关的自增

mysql - 如何在 MySql 中将默认值设置为 sysdate?

具有同步 IDENTITY 列的 SQL 多个表

sql - 如何在sql数据库中所有表的所有列中搜索和替换字符串的一部分

sql - 将值插入 SQL 浮点列会生成奇怪的结果

sql-server - 记录Sql服务器存储过程的开始和结束时间