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. UVA - 11374 - Airport Express(堆优化Dijkstra)

    Problem    UVA - 11374 - Airport Express Time Limit: 1000 mSec Problem Description In a small city c ...

  2. 三 Struts2 添加返回数据

    一.struts2如何获取servletAPI1.解耦和的方式获取封装后的Map对象,这种获取的map对象只有存取数据的功能. Map request = (Map) ActionContext.ge ...

  3. 23 python初学(模块和包)

    模块(module): 好处: 提高代码可维护性 + 编写代码不必从零开始 模块有三种: python标准库.第三方模块.应用程序自定义模块 另外,使用模块还可以避免函数名和变量名冲突,相同名字的函数 ...

  4. 【Topcoder 8572】TheLuckySum

    题意:给一个数\(n\),要把它分成lucky numbers的和. 问个数最少.字典序最小的方案. 思路:果断搜索.个数最少,所以迭代加深.枚举要的个数\(m\). 首先我们看\(n\)的个位.它肯 ...

  5. Linux内存管理 (15)页面迁移

    专题:Linux内存管理专题 关键词:RMAP.页面迁移. 相关章节:反向映射RMAP.内存规整. 页面迁移的初衷是为NUMA系统提供一种将进程迁移到任意内存节点的能力,后来内存规整和内存热插拔场景都 ...

  6. Codeforces Round #551 (Div. 2) EF Solution

    E. Serval and Snake 对于一个矩形,如果蛇的一条边与它相交,就意味着这条蛇从矩形内穿到矩形外,或者从矩形外穿到矩形内.所以如果某个矩形的答案为偶数,意味着蛇的头尾在矩形的同一侧(内或 ...

  7. SpringCloud(5)路由网关Spring Cloud Zuul

    一个简单的微服务系统如下图: 1.为什么需要Zuul Zuul很容易实现 负载均衡.智能路由 和 熔断器,可以做身份认证和权限认证,可以实现监控,在高流量状态下,对服务进行降级. 2.路由网关 继续前 ...

  8. codeforces#983 B. XOR-pyramid (dp)

    参考博客:https://www.01hai.com/note/av137952. 题意:首先定义 (b代表一个数组) 给出一个区间,l,r,求它最大的连续子序列的函数值 分析: 定义dp[x][y] ...

  9. iOS WebView 加载本地资源(图片,文件等)

    https://www.cnblogs.com/dhui69/p/5596917.html iOS WebView 加载本地资源(图片,文件等) NSString *path = [[NSBundle ...

  10. 父元素高度设置为min-height,子元素高度设置为100%,但实际上子元素高度你知道是多少吗?

    前言 给父元素一个min-height,子元素设置height:100%. 代码 <!DOCTYPE html> <html> <head> <title&g ...