这是一个小发现.(测试环境:SQL Server 9.0.3024,SQL Server 10.50.1600)
当使用执行EXECUTE语句时,若不使用括号'()’包含需要执行的字符串,将会抛出如下错误:
不包含括号exec 'select name, object_id, principal_id, schema_id, parent_object_id, type, type_desc, create_date, modify_date, is_ms_shipped, is_published, is_schema_published, lob_data_space_id, filestream_data_space_id, max_column_id_used, lock_on_bulk_load, uses_ansi_nulls, is_replicated, has_replication_filter, is_merge_published, is_sync_tran_subscribed, has_unchecked_assembly_data, text_in_row_limit, large_value_types_out_of_row, is_tracked_by_cdc, lock_escalation, lock_escalation_desc from sys.tables'
Msg 102, Level 15, State 1, Line 1 |
字符串被截断了.
将代码改为如下内容:
包含括号exec ('select name, object_id, principal_id, schema_id, parent_object_id, type, type_desc, create_date, modify_date, is_ms_shipped, is_published, is_schema_published, lob_data_space_id, filestream_data_space_id, max_column_id_used, lock_on_bulk_load, uses_ansi_nulls, is_replicated, has_replication_filter, is_merge_published, is_sync_tran_subscribed, has_unchecked_assembly_data, text_in_row_limit, large_value_types_out_of_row, is_tracked_by_cdc, lock_escalation, lock_escalation_desc from sys.tables')
OK,一切正常!
测试了一下,若exec不使用括号包含执行语句.只能使用128个字符长度的动态语句.