sqlserver 生成脚本执行创建索引
create or alter proc SP_CreateIndex
as
begin
if exists(select * from sys.objects where name='execsql')
begin
drop table execsql;
end
create table execsql(id int identity(1,1),sqlstr varchar(1000),flag varchar(255));
--创建索引
insert into execsql(sqlstr,flag)
select 'create index IX_PK_'+a.FieldName+' on '+b.TableName+'('+a.FieldName+')' ,''from ResourceConfigurationDetail a
inner join ResourceConfiguration b
on a.FID=b.ID
where a.FieldType is not null;
--创建intime 索引
insert into execsql(sqlstr,flag)
select 'create index IX_PK_INTIME ON ' +a.tablename+'(INTIME)','' from ResourceConfiguration a;
print('创建索引脚本生成');
begin
declare @sql nvarchar(2000) ,@id int
declare cur_order cursor for --申明游标
select id,sqlstr from MultipleAnalysisFY.[dbo].[execsql] where flag<>'1' order by id
open cur_order --打开游标
fetch next from cur_order into @id,@sql
RAISERROR ('执行开始......', 10, 1) WITH NOWAIT
while @@FETCH_STATUS=0
begin
declare @info varchar(255)
set @info= @sql+'正在执行,本次id为'+convert(varchar(10),@id)+'当前时间:'+convert(varchar(100),getdate(),120);
RAISERROR (@info, 10, 1) WITH NOWAIT
begin try
set @sql= 'use MultipleAnalysisDataFY;'+@sql+';';
EXEC sp_executesql @sql;--执行脚本
declare @info1 varchar(255)
set @info1= @sql+'执行完成,当前时间:'+convert(varchar(100),getdate(),120);
update MultipleAnalysisFY.[dbo].[execsql] set flag='1' where id=@id
RAISERROR (@info1, 10, 1) WITH NOWAIT
end try
begin catch
declare @error varchar(255)
set @error='执行错误,错误信息id:'+convert(varchar(10),@id)+',错误信息:'+ERROR_MESSAGE();
RAISERROR (@error, 10, 1) WITH NOWAIT
RAISERROR (@sql, 11, 1) WITH NOWAIT
end catch
fetch next from cur_order into @id,@sql
end
close cur_order --关闭游标
DEALLOCATE cur_order--释放游标
print('任务处理完成');
drop table MultipleAnalysisFY.[dbo].[execsql];
end
end
--调用
exec SP_CreateIndex
sqlserver 生成脚本执行创建索引的更多相关文章
- SqlServer在视图上创建索引
在视图上创建索引需要三个条件: 一.视图必须绑定到架构. 要做到这点,在 CREATE VIEW 语句中,必须加上 WITH SCHEMABINDING,如果是使用企业管理器,则在设计界面的空白处点击 ...
- 在SqlServer和Oralce中创建索引
给表名A的字段A增加索引 SqlServer: if exists (select 1 from sysobjects where name='表名A' and type='u')and exists ...
- sqlserver生成脚本
1.只生成数据 2.只生成架构 3.生成数据和架构
- linux环境给mongodb创建索引
首先我们来了解索引,如果有基础的可以直接看最后面的操作. 可参照 DoNotStop 的CSDN 博客 ,全文地址请点击: https://blog.csdn.net/u013725455/artic ...
- oracle海量数据中提升创建索引的速度
基本信息情况: 数据库版本:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production 操作系统版本:Ce ...
- Solr DIH以Mysql为数据源批量创建索引
演示使用solr管理后台,以mysql为数据源,批量建索引的方法 测试于:Solr 4.5.1, mmseg4j 1.9.1, Jdk 1.6.0_45, Tomcat 6.0.37 | CentOS ...
- sqlserver,执行生成脚本时“引发类型为“System.OutOfMemoryException”的异常”(已解决)
sqlserver,执行生成脚本时“引发类型为“System.OutOfMemoryException”的异常”(已解决) 出现此错误主要是因为.sql的脚本文件过大(一般都超过100M)造成内存无法 ...
- sql 脚本创建索引
之前从没有用SqlServer数据库处理过大数据量的表,都是用Oracle,然后一般为数据量较大的表添加索引或主键都是用plsql工具,今天正好需要为一张保存于SqlServer数据库的千万级数据表增 ...
- SqlServer 使用脚本创建分发服务及事务复制的可更新订阅
原文:SqlServer 使用脚本创建分发服务及事务复制的可更新订阅 [创建使用本地分发服务器] /************************[使用本地分发服务器配置发布]*********** ...
随机推荐
- 【Python使用】使用pip安装卸载Python包(含离线安装Python包)未完成???
pip 是 Python 包管理工具,该工具提供了对Python包的查找.下载.安装.卸载的功能.Python 2.7.9 + 或 Python 3.4+ 以上版本都自带 pip 工具. pip使用( ...
- 【English】20190326
Throughput吞吐量[ˈθruˌpʊt] data movement数据移动 [ˈdetə ˈmuvmənt] How to improve the Throughput for data ...
- threejs学习笔记(一)
得到webgl的渲染管线
- 三种方法实现Hadoop(MapReduce)全局排序(1)
我们可能会有些需求要求MapReduce的输出全局有序,这里说的有序是指Key全局有序.但是我们知道,MapReduce默认只是保证同一个分区内的Key是有序的,但是不保证全局有序.基于此,本文提供三 ...
- 必须掌握的MySQL优化指南
当 MySQL 单表记录数过大时,增删改查性能都会急剧下降,本文会提供一些优化参考,大家可以参考以下步骤来优化. 单表优化 除非单表数据未来会一直不断上涨,否则不要一开始就考虑拆分,拆分会带来逻辑.部 ...
- 全局css控制<td>标签属性
td { text-align: center; /*设置水平居中*/ vertical-align: middle; /*设置垂直居中*/ height:50px; / ...
- vue中使用LESS、SASS、stylus
less的使用 npm install less less-loader --save 修改webpack.config.js文件.vue.cli 搭建项目可跳过此步 { test: /\.less$ ...
- Masonry 与 frame 混用导致的问题
https://www.jianshu.com/p/357fab4b84e7 Masonry 与 frame 混用可能出现子控件大小跟预期不一致的情况,具体是什么样呢? 例如,自定义一个 UIView ...
- 【学习总结】GirlsInAI ML-diary day-15-读/写txt文件
[学习总结]GirlsInAI ML-diary 总 原博github链接-day15 认识读/写txt文件 路径: 绝对路径:文件在电脑中的位置 相对路径:下面会用到 1-准备 新建一个 pytho ...
- 查看CLOUD系统级IIS日志
1.进入IIS,点击查看日志文件 2.分不同文件夹存放