1、一个begin..end与多个的区别
多个 + exception 操作可以更好的、更详细的 捕捉到 sql语句的异常
2、如果需要创建 随SQL server服务 自启动的存储过程需要注意:
必需由管理员在master表中创建 or 使用语句 exec sp_procoption '存储过程名','startup','on' 将存储过程设置为自启动
====================================================================================
3、存储过程中 使用 临时表
--临时表 存储需要处理的 表 ID if object_id('#tempObjectIDAA') is not null drop table #tempObjectIDAA go create table #tempObjectIDAA( ID int identity(1,1), object_id int, --表 ID avg_fragmentation decimal --碎片百分比 * 100 ) --正确。向临时表中插入数据 insert into #tempObjectIDAA(object_id,avg_fragmentation) select object_id,avg_fragmentation_in_percent from sys.dm_db_index_physical_stats (@db_id,null,null,null,'LIMITED') where avg_fragmentation_in_percent >10 and fragment_count > 10 --and index_id > 0; --错误。因为这种语法,会新建一个表 --select object_id,avg_fragmentation_in_percent into #tempObjectIDAA from sys.dm_db_index_physical_stats (@db_id,null,null,null,'LIMITED') where avg_fragmentation_in_percent >10 and fragment_count > 10 and index_id > 0;