Upgrade Image&ntext to varbinarymax&nvarchar(max)
CREATE PROCEDURE SP_EXEC_WITH_LOG(@I_TICKETNO VARCHAR(10),@I_SQLSTR nvarchar(max))
AS
BEGIN
DECLARE @QUOTATION_TRANSFER_STR nvarchar(max);
SET @QUOTATION_TRANSFER_STR = REPLACE(@I_SQLSTR,'''','''''');
BEGIN TRY
EXEC SP_EXECUTESQL @I_SQLSTR;
EXEC GPUPGRADE_LOGGING @I_TICKETNO,@QUOTATION_TRANSFER_STR,'SUCCESS',0
END TRY
BEGIN CATCH
declare @message varchar(2000);
select @message = ERROR_MESSAGE();
EXEC GPUPGRADE_LOGGING @I_TICKETNO,@QUOTATION_TRANSFER_STR,@message,1
END CATCH
END
GO
CREATE PROCEDURE UPDATE_IMAGE_TO_VARBINARYMAX
AS
BEGIN
declare @vstr nvarchar(1000);
declare @vtabname nvarchar(100);
declare @vSchemaName nvarchar(100);
declare @vcolumnName nvarchar(100);
declare c_table cursor scroll for select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where DATA_TYPE='image' and (table_schema='gpglobal' or table_schema like 'gpcomp%');
declare c_view cursor scroll for select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where DATA_TYPE='image' and table_schema ='dbo';
declare c_small_table cursor scroll for
select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS
where DATA_TYPE='varbinary'
and CHARACTER_MAXIMUM_LENGTH=-1
and (table_schema='gpglobal' or table_schema like 'gpcomp%')
and TABLE_NAME not like '%_arch';
open c_table;
fetch first from c_table into @vSchemaName,@vtabname,@vcolumnName;
while @@fetch_status = 0
begin
set @vstr = '';
set @vstr = N'ALTER TABLE '+@vSchemaName+'.'+@vtabname+' ALTER COLUMN '+@vcolumnName+' VARBINARY(MAX)';
print @vstr;
exec SP_EXECUTESQL @vstr;
fetch next from c_table into @vSchemaName,@vtabname,@vcolumnName;
end;
close c_table;
deallocate c_table;
set @vSchemaName = '';
set @vtabname = '';
set @vcolumnName = '';
open c_view;
fetch first from c_view into @vSchemaName,@vtabname,@vcolumnName;
while @@fetch_status = 0
begin
set @vstr = '';
set @vstr = N'DROP VIEW ['+ @vSchemaName+'].['+@vtabname +']';
print @vstr;
exec SP_EXECUTESQL @vstr;
set @vstr = '';
set @vstr = N'CREATE VIEW ['+ @vSchemaName+'].['+@vtabname +'] AS SELECT * FROM GPGLOBAL.'+@vtabname ;
print @vstr;
exec SP_EXECUTESQL @vstr;
fetch next from c_view into @vSchemaName,@vtabname,@vcolumnName;
end;
close c_view;
deallocate c_view;
set @vSchemaName = '';
set @vtabname = '';
set @vcolumnName = '';
open c_small_table;
fetch first from c_small_table into @vSchemaName,@vtabname,@vcolumnName;
while @@fetch_status = 0
begin
set @vstr = '';
set @vstr = N'UPDATE '+@vSchemaName+'.'+@vtabname+' SET '+@vcolumnName+' = '+@vcolumnName;
print @vstr;
exec SP_EXECUTESQL @vstr;
set @vstr = N'ALTER INDEX ALL ON ' +@vSchemaName+'.'+@vtabname+ ' reorganize WITH (LOB_COMPACTION=ON)';
print @vstr;
exec SP_EXECUTESQL @vstr;
fetch next from c_small_table into @vSchemaName,@vtabname,@vcolumnName;
end;
close c_small_table;
deallocate c_small_table;
END
GO
CREATE PROCEDURE UPDATE_NTEXT_TO_VARCHARMAX
AS
BEGIN
declare @vstr nvarchar(1000);
declare @vtabname nvarchar(100);
declare @vSchemaName nvarchar(100);
declare @vcolumnName nvarchar(100);
declare c_table cursor scroll for select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where DATA_TYPE='ntext' and (table_schema='gpglobal' or table_schema like 'gpcomp%');
declare c_view cursor scroll for select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS where DATA_TYPE='ntext' and table_schema ='dbo';
declare c_small_table cursor scroll for
select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME from INFORMATION_SCHEMA.COLUMNS
where DATA_TYPE='nvarchar'
and CHARACTER_MAXIMUM_LENGTH=-1
and (table_schema='gpglobal' or table_schema like 'gpcomp%')
and TABLE_NAME not like '%_arch'
and TABLE_NAME not in(
'GPRECL'
,'GPPROB'
,'GPCRDLOGS'
,'GPCUSTBLOB'
,'GPRECLLOG'
,'GPACTV'
);
open c_table;
fetch first from c_table into @vSchemaName,@vtabname,@vcolumnName;
while @@fetch_status = 0
begin
set @vstr = '';
set @vstr = N'ALTER TABLE '+@vSchemaName+'.'+@vtabname+' ALTER COLUMN '+@vcolumnName+' NVARCHAR(MAX)';
print @vstr;
exec SP_EXECUTESQL @vstr;
fetch next from c_table into @vSchemaName,@vtabname,@vcolumnName;
end;
close c_table;
deallocate c_table;
set @vSchemaName = '';
set @vtabname = '';
set @vcolumnName = '';
open c_view;
fetch first from c_view into @vSchemaName,@vtabname,@vcolumnName;
while @@fetch_status = 0
begin
set @vstr = '';
set @vstr = N'DROP VIEW ['+ @vSchemaName+'].['+@vtabname +']';
print @vstr;
exec SP_EXECUTESQL @vstr;
set @vstr = '';
set @vstr = N'CREATE VIEW ['+ @vSchemaName+'].['+@vtabname +'] AS SELECT * FROM GPGLOBAL.'+@vtabname ;
print @vstr;
exec SP_EXECUTESQL @vstr;
fetch next from c_view into @vSchemaName,@vtabname,@vcolumnName;
end;
close c_view;
deallocate c_view;
set @vSchemaName = '';
set @vtabname = '';
set @vcolumnName = '';
open c_small_table;
fetch first from c_small_table into @vSchemaName,@vtabname,@vcolumnName;
while @@fetch_status = 0
begin
set @vstr = '';
set @vstr = N'UPDATE '+@vSchemaName+'.'+@vtabname+' SET '+@vcolumnName+' = '+@vcolumnName;
print @vstr;
exec SP_EXECUTESQL @vstr;
set @vstr = N'ALTER INDEX ALL ON ' +@vSchemaName+'.'+@vtabname+ ' reorganize WITH (LOB_COMPACTION=ON)';
print @vstr;
exec SP_EXECUTESQL @vstr;
fetch next from c_small_table into @vSchemaName,@vtabname,@vcolumnName;
end;
close c_small_table;
deallocate c_small_table;
END
GO
exec UPDATE_IMAGE_TO_VARBINARYMAX;
GO
exec UPDATE_NTEXT_TO_VARCHARMAX;
GO
drop PROCEDURE UPDATE_IMAGE_TO_VARBINARYMAX;
go
drop PROCEDURE UPDATE_NTEXT_TO_VARCHARMAX;
GO
SELECT * FROM gpmainuser.UPGRADE_LOG;
GO
select * from INFORMATION_SCHEMA.COLUMNS where DATA_TYPE='nvarchar' and TABLE_SCHEMA='GPcomp1'
UPDATE gpcomp1.GARECEIPT_ARCH SET FEED_DATA = FEED_DATA;
select TABLE_SCHEMA,TABLE_NAME,COLUMN_NAME
from INFORMATION_SCHEMA.COLUMNS i , sys.index_columns idx
where DATA_TYPE='ntext' and (table_schema='gpglobal' or table_schema like 'gpcomp%');
select s.name,o.name,I.name,c.name,t.name
from
sys.columns c,
sys.index_columns ic ,
sys.indexes i ,
sys.objects o,
sys.schemas s,
sys.types t
where i.object_id = ic.object_id
and i.index_id = ic.index_id
and i.object_id = o.object_id
and s.schema_id = o.schema_id
and ic.column_id =c.column_id
and t.system_type_id = c.system_type_id
and (s.name ='gpglobal' or s.name like 'gpcomp%')
and o.name ='GPRECL'
and c.name = 'REMARKS'
and t.name = 'ntext'
select distinct s.name,o.name,i.name,c.name,t.name
from
sys.columns c,
sys.index_columns ic ,
sys.indexes i ,
sys.objects o,
sys.schemas s,
sys.types t
where i.object_id = ic.object_id
and i.index_id = ic.index_id
and i.object_id = o.object_id
and s.schema_id = o.schema_id
and ic.column_id = c.column_id
and ic.object_id = c.object_id
and t.system_type_id = c.system_type_id
and (s.name ='gpglobal' or s.name like 'gpcomp%')
and o.name ='GPCRDLOGS'
and t.name = 'ntext'
select * from sys.indexes
select * from sys.index_columns
select * from sys.columns
select * from sys.objects where name ='GPCRDLOGS'
select * from sys.schemas
select * from sysindexes
select * from sys.types
select * from sys.data_spaces;
select * from sysindexes
select object_name(id) tablename,
8*reserved/1024 reservedMB,
rtrim(8*dpages/1024)+'Mb' used,
8*(reserved-dpages)/1024 unused,
8*dpages/1024-rows/1024*minlen/1024 free,rows,*
from sysindexes
where indid=1 AND object_name(id)='GPCRDLOGS'
order by reserved desc
exec sp_spaceused N'GPCOMP1.GPCRDLOGS'
exec sp_refreshview N'gpcomp1.aa'
http://connect.microsoft.com/SQLServer/feedback/details/669621/sp-refreshview-fails-for-views-that-were-created-without-explicitly-qualifying-their-schema-name
http://mitchelsellers.com/blogs/2007/07/27/determing-sql-server-table-size.aspx
http://therightstuff.de/CommentView,guid,df930155-f60f-4f56-ab33-f1352ff091a1.aspx
http://msdn.microsoft.com/en-us/library/hh245121.aspx
http://technet.microsoft.com/zh-cn/library/ms162833.aspx
http://technet.microsoft.com/zh-cn/library/ms162808%28v=sql.105%29.aspx
http://technet.microsoft.com/zh-cn/library/ms162843.aspx
http://technet.microsoft.com/zh-cn/library/ms180944.aspx
http://technet.microsoft.com/en-us/library/ms188603%28v=sql.105%29.aspx
http://blogs.msdn.com/b/sqlserverfaq/archive/2008/10/14/sql-server-can-perform-slow-after-changing-the-cost-threshold-for-parallelism.aspx
http://sqlblog.com/blogs/jonathan_kehayias/archive/2010/01/19/tuning-cost-threshold-of-parallelism-from-the-plan-cache.aspx
http://www.mssqlcity.com/Articles/Undoc/SQL2000UndocSP.htm
http://my.oschina.net/tangyu/blog/79120
http://sqlmag.com/t-sql/varbinarymax-tames-blob
http://www.poorren.com/sqlserver-2005-varcharmax-nvarcharmax-varbinarymax/
http://blog.csdn.net/xianshengsun/article/details/7657654
http://blog.csdn.net/xianshengsun/article/details/7657551
Determing SQL Server Table Size
Upgrade Image&ntext to varbinarymax&nvarchar(max)的更多相关文章
- SQL 2005中char、nchar、varchar、ntext and nvarchar(max)的区别
原文地址 MS SQL大值数据类型varchar(max).nvarchar(max).varbinary(max) 在MS SQL2005及以上的版本中,加入大值数据类型(varchar(max). ...
- nvarchar(MAX) 、ntext的差别
今天在做一个项目时,程序成功向数据库插入一条数据, 插入的是一篇比较大的文章,而且还有很多样式. Id是int型,Content用的是 ntext类型的 但是当我在手动改数据库Id时出现错误: 错误源 ...
- sql中nvarchar(max)长度测试
nvarchar(max)长度测试:在使用convert强制类型转化之后 文本长度可以突破8000的上限.并且nvarchar(max)的最大长度可达到2^31以下为验证SQL: Declare @A ...
- MS SQL大值数据类型varchar(max)、nvarchar(max)、varbinary(max)
在MS SQL2005及以上的版本中,加入大值数据类型(varchar(max).nvarchar(max).varbinary(max) ).大值数据类型最多可以存储2^30-1个字节的数据. 这几 ...
- Sql server中的 nvarchar(max) 到底有多大?(转载)
问题: SQL server中的nvarchar(max)最大的长度是4000个字吗? 如果字段的内容超过4000个字时用什么类型呢?text 还是binary?他们的最大长度是多少?比如字段放的是长 ...
- 关于varchar(max), nvarchar(max)和varbinary(max)
在MS SQL2005及以上的版本中,加入大值数据类型(varchar(max).nvarchar(max).varbinary(max) ).大值数据类型最多可以存储2^30-1个字节的数据.这几个 ...
- SQL Server中VARCHAR(MAX)和NVARCHAR(MAX)使用时要注意的问题(转载)
在Microsoft SQLServer2005及以上的版本中,对于varchar(n).nvarchar(n)和varbinary(n)有了max的扩展.可以使用如:varchar(max).nva ...
- sql中NVARCHAR(MAX) 性能和占空间分析 varchar(n),nvarchar(n) 长度性能及所占空间分析
varchar(n),nvarchar(n) 中的n怎么解释: nvarchar(n)最多能存n个字符,不区分中英文. varchar(n)最多能存n个字节,一个中文是两个字节. 所占空间: nvar ...
- --查询nvarchar(max)的表和字段
--查询nvarchar(max)的表和字段 select 'insert into #tempTabelInfo select '''+d.name+''', '''+a.name+''', max ...
随机推荐
- CentOS网卡配置文件
[root@xaiofan ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0TYPE=EthernetONBOOT=yesNM ...
- mysql下面的INSTALL-BINARY的内容,所有的mysql的配置内容都在这
2.2 Installing MySQL on Unix/Linux Using Generic Binaries Oracle provides a set of binary distributi ...
- virtual box ubuntu卡在开机光标
创建虚拟机的时候选择之前保存的虚拟机盘vdi文件,打开的时候卡在光标.原来是因为虚拟机是64位的,但是新建的时候只有32位的ubuntu可以选择就选择的32位. 解决办法: 在bios设置里,打开cp ...
- IO的生命周期
● 将来自cache的数据封装成bio submit_bh->submit_bh_wbc 此时IO还在fs层 ● 进入block IO层 submit_bh_wbc->submit_io- ...
- Redis 笔记与总结4 set 和 zset 类型
(一)set 类型 set 是集合是 string 类型的无序集合. set 元素最大可以包含(2 的 32 次方)个元素.set 的是通过 hash table 实现的,所以添加.删除和查找的复杂度 ...
- Socket简介
本文全部摘抄http://c.biancheng.net/cpp/html/3029.html 大多数项目是在Linux下开发服务器端,而在Windows下开发客户端,需要经常在两大平台之间进行切换, ...
- 表单序列化 js
function serliaze(form) { //序列化表单 var obj = {}; $.each(form.serializeArray(), function (index) { if ...
- prepare PDO
<?php $sql='SELECT email FROM users WHERE id = :id'; $statement=$pdo->prepare($sql);$userId=fi ...
- page fault rate
COMPUTER ORGANIZATION AND ARCHITECTURE DESIGNING FOR PERFORMANCE NINTH EDITION A program computes th ...
- Delphi 200X、XE中如何用并行实现循环的计算
interface uses Classes, SysUtils; type TParallelProc = reference to procedure(i: Integer; ThreadID: ...