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. Python开发【内置模块篇】collections

    namedtuple namedtuple是一个函数,它用来创建一个自定义的tuple对象,并且规定了tuple元素的个数,并可以用属性而不是索引来引用tuple的某个元素. 这样一来,我们用name ...

  2. windows环境:idea或者eclipse指定用户名操作hadoop集群

    方法 在系统的环境变量或java JVM变量添加HADOOP_USER_NAME(具体值视情况而定). 比如:idea里面可以如下添加HADOOP_USER_NAME=hdfs 原理:直接看源码 /h ...

  3. java 常用工具整理

    mapUtil map操作工具类 <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-collections4 ...

  4. mysql 报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executin

    解决办法1. 修改用户密码mysql> alter user 'root'@'localhost' identified by 'youpassword'; 或者 mysql> set p ...

  5. KEIL_MDK生成Bin文件

    1.MDK配置 MDK是使用安装目录下的(formelf.exe)工具来生成bin文件,配置方法:勾选 "Run # 1",在后面输入框写入bin文件生成方式 2.绝对路径 &qu ...

  6. 互怼、IPO、雷潮、寒冬,2018 互联网圈的那些事儿

    有了人的地方,就会有江湖. 有江湖的地方,就会有门派. 有门派的地方,就会有纷争. 有纷争的地方,就会有兴衰. 2018年马上就要离我们远去了,迎接我们的将会是新的一年——2019年.在整个过去的20 ...

  7. 2019阿里P7最新总结Spring Boot面试问题

        Spring Boot一直是Spring生态系统的关键参与者.该项目通过其自动配置功能使我们的生活更加轻松.在本教程中,我们将介绍在求职面试中可能出现的一些与Spring Boot相关的最常见 ...

  8. python dlib opencv 人脸68点特征检测

    不得不感慨,现在现成的东西太多了,直接拿来用就行了 dlib安装(指定版本安装,避免踩坑) pip dlib中训练好的文件http://dlib.net/files/shape_predictor_6 ...

  9. C# Note36: .NET unit testing framework

    It’s usually good practice to have automated unit tests while developing your code. Doing so helps y ...

  10. Tampermonkey-让百度云下载飞起来

    1. 简介Tampermonkey是一款免费的浏览器扩展程序. 我们这里用于谷歌浏览器,目的是为了让百度云里面的文件以满速下载,节约金钱. 2. 安装安装Lantern蓝灯或者其他的FQ工具. 打开F ...