sp_tableoption的作用是设置表选项,影响表的某些特定行为,OBJECTPROPERTY 函数用于查看对象的属性。
一,sp_tableoption
Sets option values for user-defined tables. sp_tableoption can be used to control the in-row behavior of tables with varchar(max), nvarchar(max), varbinary(max), xml, text, ntext, image, or large user-defined type columns.
The text/ntext,image in row feature will be removed in a future version of SQL Server. To store large value data, we recommend that you use of the varchar(max), nvarchar(max) and varbinary(max) data types.
Syntax
sp_tableoption [ @TableNamePattern = ] ‘table‘ , [ @OptionName = ] ‘option_name‘ ,[ @OptionValue =] ‘value‘
[ @TableNamePattern =] ‘table‘
Is the qualified or nonqualified name of a user-defined database table.
[ @OptionName = ] ‘option_name‘
Value |
Description |
---|---|
table lock on bulk load |
When disabled (the default), it causes the bulk load process on user-defined tables to obtain row locks. When enabled, it causes the bulk load processes on user-defined tables to obtain a bulk update lock. |
large value types out of row |
1 = varchar(max), nvarchar(max), varbinary(max), xml and large user-defined type (UDT) columns in the table are stored out of row, with a 16-byte pointer to the root. 0 = varchar(max), nvarchar(max), varbinary(max), xml and large UDT values are stored directly in the data row, up to a limit of 8000 bytes and as long as the value can fit in the record. If the value does not fit in the record, a pointer is stored in-row and the rest is stored out of row in the LOB storage space. 0 is the default value. |
[ @OptionValue =] ‘value‘
Is whether the option_name is enabled (TRUE, ON, or 1) or disabled (FALSE, OFF, or 0). value is varchar(12), with no default. value is case insensitive.
Remarks
sp_tableoption can be used only to set option values for user-defined tables. To display table properties, use OBJECTPROPERTY.
二,OBJECTPROPERTY
Returns information about schema-scoped objects in the current database.
Syntax
OBJECTPROPERTY ( id , property )
property
Is an expression that represents the information to be returned for the object specified by id.
Property name |
Object type |
Description and values returned |
---|---|---|
TableIsLockedOnBulkLoad |
Table |
Table is locked due to a bcp or BULK INSERT job. 1 = True 0 = False |
Return type: int
三,用法示例
1,设置表的option
exec sys.sp_tableoption @TableNamePattern=‘[dbo].[UserCDC]‘, @OptionName =‘table lock on bulk load‘, @OptionValue =‘true‘
2,查看表的property
select OBJECTPROPERTY(object_id(‘[dbo].[UserCDC]‘),N‘TableIsLockedOnBulkLoad‘)
参考文档:
https://msdn.microsoft.com/zh-cn/library/ms173530.aspx
https://msdn.microsoft.com/zh-cn/library/ms176105.aspx