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 生成脚本执行创建索引的更多相关文章

  1. SqlServer在视图上创建索引

    在视图上创建索引需要三个条件: 一.视图必须绑定到架构. 要做到这点,在 CREATE VIEW 语句中,必须加上 WITH SCHEMABINDING,如果是使用企业管理器,则在设计界面的空白处点击 ...

  2. 在SqlServer和Oralce中创建索引

    给表名A的字段A增加索引 SqlServer: if exists (select 1 from sysobjects where name='表名A' and type='u')and exists ...

  3. sqlserver生成脚本

    1.只生成数据 2.只生成架构 3.生成数据和架构

  4. linux环境给mongodb创建索引

    首先我们来了解索引,如果有基础的可以直接看最后面的操作. 可参照 DoNotStop 的CSDN 博客 ,全文地址请点击: https://blog.csdn.net/u013725455/artic ...

  5. oracle海量数据中提升创建索引的速度

    基本信息情况: 数据库版本:Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production 操作系统版本:Ce ...

  6. Solr DIH以Mysql为数据源批量创建索引

    演示使用solr管理后台,以mysql为数据源,批量建索引的方法 测试于:Solr 4.5.1, mmseg4j 1.9.1, Jdk 1.6.0_45, Tomcat 6.0.37 | CentOS ...

  7. sqlserver,执行生成脚本时“引发类型为“System.OutOfMemoryException”的异常”(已解决)

    sqlserver,执行生成脚本时“引发类型为“System.OutOfMemoryException”的异常”(已解决) 出现此错误主要是因为.sql的脚本文件过大(一般都超过100M)造成内存无法 ...

  8. sql 脚本创建索引

    之前从没有用SqlServer数据库处理过大数据量的表,都是用Oracle,然后一般为数据量较大的表添加索引或主键都是用plsql工具,今天正好需要为一张保存于SqlServer数据库的千万级数据表增 ...

  9. SqlServer 使用脚本创建分发服务及事务复制的可更新订阅

    原文:SqlServer 使用脚本创建分发服务及事务复制的可更新订阅 [创建使用本地分发服务器] /************************[使用本地分发服务器配置发布]*********** ...

随机推荐

  1. Jenkins之Job建立-运行本地脚本

    新建一个自由风格的项目,运行本地脚本 1.点击菜单栏中的“新任务” 2.进入该页面后输入一个项目名称,然后选择“构建一个自由风格的软件项目”,滑动到最底端,点击ok(在左下角) 3.进入下图页面后 “ ...

  2. Vue 自定义一个插件的用法、小案例及在项目中的应用

    1.开发插件 install有两个参数,第一个是Vue构造器,第二个参数是一个可选的选项对象   MyPlugin.install = function (Vue, options) {   // 1 ...

  3. 文本分类实战(八)—— Transformer模型

    1 大纲概述 文本分类这个系列将会有十篇左右,包括基于word2vec预训练的文本分类,与及基于最新的预训练模型(ELMo,BERT等)的文本分类.总共有以下系列: word2vec预训练词向量 te ...

  4. Asp.Net WebApi 使用OWIN架构后,出现 “没有 OWIN 身份验证管理器与此请求相关联(No OWIN authentication manager is associated with the request)” 异常的解决办法

    在Asp.Net WebApi 项目中使用OWIN模块之后,如果没有在OWIN的Startup类中配置认证方式,调用WebApi的相关Controller和Action就会出现如下异常: 出现错误. ...

  5. mybatis从mapper接口跳转到相应的xml文件的eclipse插件

    mybatis从mapper接口跳转到相应的xml文件的eclipse插件 前提条件 开发软件 eclipse 使用框架 mybatis 为了方便阅读源码,项目使用mybatis的时候,方便从mapp ...

  6. 基于 HTML5 结合工业互联网的智能飞机控制

    前言 从互联网+的概念一出来,就瞬间吸引了各行各业的能人志士,想要在这个领域分上一杯羹.现在传统工业生产行业运用互联网+的概念偏多,但是在大众创业万众创新的背景下,“互联网+”涌出了层出不穷的“玩法” ...

  7. docker私有镜像仓库搭建

    环境:centos7,dockere版本:18.09.0,镜像仓库:v2 docker-registry:192.168.137.101   docker私有仓库服务器 docker-app: 192 ...

  8. 基于mybatis基本操作

    实体 在对上述三个实体操作中了解mybatis的实现 全部代码 pro1是另外的一个完整项目用spring和struts2 hibernate 下载  https://github.com/Danov ...

  9. 酷炫的loading

    今天分享一下,怎么通过用css写出一个酷炫的loading. meta: <meta name="viewport" content="width=device-w ...

  10. 其它综合-有趣的linux命令行工具-lolcat

    lolcat :一个在 Linux 终端中输出彩虹特效的命令行工具 何为Lolcat Lolcat 是一个针对 Linux,BSD 和 OSX 平台的工具,它类似于 cat,并为 cat 的输出添加彩 ...