这是一个小发现.(测试环境: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
Incorrect syntax near 'select name,
        object_id,
        principal_id,
        schema_id,
        parent_object_id,
        type,
        type_desc,
        create_date,
        modify_d'.

 

字符串被截断了.

将代码改为如下内容:

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个字符长度的动态语句.

exec

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-08-31
  • 2022-01-08
  • 2021-11-04
  • 2021-12-17
  • 2021-10-13
  • 2022-12-23
猜你喜欢
  • 2021-10-13
  • 2022-12-23
  • 2021-08-05
  • 2021-12-19
  • 2021-08-15
  • 2021-08-01
  • 2021-05-26
相关资源
相似解决方案