if exists(select 1 from sysobjects where name = 'sp_gent' and type = 'P')
drop procedure sp_gent
go
create procedure sp_gent
@tblname varchar(30) = null,
@prechar varchar(4) = null, --$:no print
@table_dll varchar(16384) = null out,
@dbname varchar(32) = null,
@droptg char(1) = '1',
@prxytx varchar(255) = null,
@replace varchar(20) = null,
@tabtype varchar(1) = 'A', --A:所有表;P:代理表;U:用户表
@indextg varchar(3) = 'TPI', --T:纯表;P:主键;I:纯索引;J:除主键外的纯索引(和TP使用与I相同,和I同时使用I失效)
@table_seg varchar(32) = null,
@index_seg varchar(32) = null
as
begin
set nocount on
if @tblname is null begin
declare @c_tblname varchar(30)
declare cur_1 cursor for
select name from sysobjects where type = 'U' order by name
open cur_1
fetch cur_1 into @c_tblname
while @@sqlstatus = 0 begin
exec sp_gent
@tblname = @c_tblname,
@prechar = @prechar,
@dbname = @dbname ,
@droptg = @droptg ,
@prxytx = @prxytx ,
@replace = @replace,
@tabtype = @tabtype, --A:所有表;P:代理表;U:用户表
@indextg = @indextg, --A:表和索引;T:纯表;I:纯索引
@table_seg = @table_seg,
@index_seg = @index_seg
fetch cur_1 into @c_tblname
end
close cur_1
deallocate cursor cur_1
return
end
declare @obj_id int
declare @sysstat2 int
declare @username varchar(30)
select @obj_id = id, @sysstat2 = sysstat2 ,@username = user_name(uid)
from sysobjects where name = @tblname and type = 'U'
if @@rowcount <> 1
begin
print 'table %1! not exists', @tblname
goto err
end
if @sysstat2 & 1024 = 1024 begin
if upper(@tabtype) in ('U')
goto ok
end
else begin
if upper(@tabtype) in ('P')
goto ok
end
declare @colname varchar(30) --列名
declare @typename varchar(30) --类型名称
declare @usertype smallint --类型ID
declare @length int --长度
declare @prec tinyint --有效位数
declare @scale tinyint --精度
declare @def_id int --默认值id
declare @nulls tinyint --空值
declare @ident tinyint --标识列
declare @index_dll varchar(16384)
declare @def_text varchar(100)
declare @ide_text varchar(30)
declare @nul_text varchar(30)
declare @cns_text varchar(500)
declare @uni_pri varchar(40), @non_clu varchar(40), @non_uni varchar(40)
declare @lock_scheme varchar(100)
declare @keys varchar(500), @i int
declare @thiskey varchar(30)
declare @sorder char(4)
select @keys = "", @i = 1
declare @cns_name varchar(30), @status int, @indid int
declare @idx_name varchar(50)
declare @CRNW varchar(2) --回车换行
declare @TAB char(1)
select @CRNW = convert(varchar(2), 0x0d0a)
select @TAB = convert(char(1), 0x09)
declare @dbname_dot varchar(35)
if ltrim(@dbname) is null
select @dbname = null,@dbname_dot = null
else
select @dbname = @dbname + '.',@dbname_dot = @dbname + '..'
declare @table_name varchar(30)
select @table_name = case when ltrim(@replace) is not null then @replace else @tblname end
declare @prefix_table varchar(2)
select @prefix_table = case when ltrim(@prxytx) is not null then 'r_' else null end
if charindex('T',@indextg) > 0 begin
if @droptg <> '0'
select @table_dll = "if exists(select 1 from "+@dbname_dot
+"sysobjects where name = '"+@prefix_table
+@table_name+"' and type = 'U')"
+@CRNW+@TAB+'drop table '+@dbname+@username + '.'
+@prefix_table
+@table_name+@CRNW
+case when @sysstat2 & 1024 = 1024
then @TAB+'exec sp_dropobjectdef '+@table_name+@CRNW
when ltrim(@prxytx) is not null
then @TAB+'exec sp_dropobjectdef r_'+@table_name+@CRNW
else null
end
+'go'+@CRNW
else
select @table_dll = null
if @sysstat2 & 1024 = 1024 begin
declare @OS_file varchar(255)
select @OS_file = char_value from sysattributes
where class = 9 and attribute = 1 and
object_cinfo = @tblname
if @@rowcount = 0 begin
print '取代理表前缀失败%1!', @tblname
goto err
end
select @table_dll = @table_dll+"exec sp_addobjectdef "
+@table_name
+", '"+@OS_file+"', 'table'"+@CRNW+
"create existing table " + @dbname+@username + "."
+@table_name + " ("
end
else if ltrim(@prxytx) is not null
select @table_dll = @table_dll+"exec sp_addobjectdef r_"
+@table_name+", '"+@prxytx
+@table_name+"', 'table'"+@CRNW
+"create existing table " + @dbname+@username + ".r_"
+@table_name + " ("
else
select @table_dll = @table_dll+'create table ' + @dbname+@username + '.'
+@table_name + ' ('
--如果在sybsystemprocs数据库下提交,以下注释掉
declare @tablna varchar(255)
--select @tablna = tablna from knp_tabl where tablcd = @tblname
--if @@rowcount = 0
select @tablna = null
if ltrim(@tablna) is not null
select @table_dll = @table_dll + ' --'+@tablna
select @prechar = case when @prechar is not null then left(@prechar+space(4),4) else @prechar end
if @prechar <> '$' begin
if @prechar is not null begin
declare @temp_dll varchar(16384),@print_dll varchar(16384)
select @temp_dll = @table_dll
select @temp_dll = @prechar + @temp_dll
while charindex(@CRNW,@temp_dll) > 0 and char_length(@temp_dll) <> charindex(@CRNW,@temp_dll)+1 begin
select @print_dll = @print_dll + left(@temp_dll,charindex(@CRNW,@temp_dll) - 1) + @CRNW+@prechar
select @temp_dll = substring(@temp_dll,charindex(@CRNW,@temp_dll)+char_length(@CRNW),char_length(@temp_dll))
end
select @print_dll = @print_dll + @temp_dll
print '%1!',@print_dll
end
else
print '%1!',@table_dll
end
select @table_dll = @table_dll + @CRNW
if ltrim(@table_seg) is null begin
select @table_seg = s.name
from sysobjects o, syssegments s, sysindexes i
where o.id = object_id(@tblname)
and i.id = o.id
and i.indid < 2
and i.segment = s.segment
if @@rowcount = 0 begin
print '表%1!所在的段不存在',@tblname
goto err
end
end
end
--确定表是否有完整性约束
declare @have_con char(1)
if exists (select 1 from sysindexes where id = @obj_id and status2 & 2 = 2 )
and (ltrim(@prxytx) is null or @sysstat2 & 1024 = 1024)
select @have_con = '1'
else
select @have_con = '0'
if charindex('T',@indextg) > 0 begin
declare @col_int int
select @col_int = count(*) from syscolumns
where id = @obj_id
declare cur_col cursor for
select b.name, b.usertype, c.name , b.length, b.prec, b.scale, b.cdefault,
convert(bit,b.status&8) as Nulls,
convert(bit,b.status&128) as Ident
from sysobjects a, syscolumns b, systypes c
where a.name = @tblname and a.type = 'U'
and a.id = b.id
and b.usertype = c.usertype
order by b.colid
open cur_col
fetch cur_col into @colname, @usertype, @typename, @length, @prec, @scale, @def_id, @nulls, @ident
while @@sqlstatus = 0
begin
--系统定义的数据类型
if @usertype < 100
begin
if rtrim(@typename) in ('char','varchar','nchar','nvarchar')
select @typename = @typename + '('+ convert(varchar,@length) +')'
else if @typename in ('numeric','decimal')
select @typename = @typename + '(' + convert(varchar,@prec) + ',' + convert(varchar,@scale) + ')'
else if @typename in ('float','double')
select @typename = @typename + '(' + convert(varchar,@prec) + ')'
else if @typename in ('binary','varbinary')
select @typename = @typename + '(' + convert(varchar,@length) + ')'
end
select @ide_text = case @ident when 1 then 'identity' else null end
select @nul_text = case @nulls when 1 then ' null' else 'not null' end
if @def_id > 0
begin
select @def_text = ltrim(rtrim(b.text))
from sysobjects a, syscomments b
where a.id = @def_id and a.id = b.id
if @@rowcount <> 1
begin
print '取default失败%1!', @def_id
goto err
end
while charindex(@TAB,@def_text) > 0
select @def_text = stuff(@def_text,charindex(@TAB,@def_text),char_length(@TAB),' ')
while charindex(' ',@def_text) > 0
select @def_text = stuff(@def_text,charindex(' ',@def_text),char_length(' '),' ')
select @def_text = rtrim(ltrim(@def_text))
end
else
select @def_text = null
declare @thiscol varchar(500)
select @thiscol =
case when char_length(@colname) <= 10 then left(@colname+space(10),10) else @colname end
+ ' ' + case when char_length(@typename) <= 15 then left(@typename+space(15),15) else @typename end
+ ' ' + @def_text
+ ' ' + @ide_text
+ ' ' + @nul_text
if @i = @col_int and (@have_con = '0' or charindex('P',@indextg) <= 0)
select @thiscol = @thiscol + ' '
else
select @thiscol = @thiscol + ' ,'
--如果在sybsystemprocs数据库下提交,以下注释掉
declare @colmna varchar(255)
select @colmna = null
--select @colmna = colmna from knp_colm where tablcd = @tblname and colmcd = @colname
if ltrim(@colmna) is not null
select @thiscol = @thiscol + ' --'+@colmna
if @prechar <> '$'
print '%1!%2!',@prechar, @thiscol
select @table_dll = @table_dll + @thiscol + @CRNW
select @i = @i + 1
fetch cur_col into @colname, @usertype, @typename, @length, @prec, @scale, @def_id, @nulls, @ident
end
end
if @have_con = '1' and charindex('P',@indextg) > 0
begin
select @cns_name = name, @status = status, @indid = indid
from sysindexes where id = @obj_id and status2 & 2 = 2
--print 'exist constraint... status = %1!', @status
if @indid = 1
select @non_clu = 'clustered'
else if @indid > 1
begin
if @status & 16 = 16
select @non_clu = 'clustered'
else
select @non_clu = 'nonclustered'
end
if @status & 2048 = 2048
select @uni_pri = 'primary key'
else
select @uni_pri = 'unique'
select @cns_text = 'constraint ' + @cns_name + ' ' + @uni_pri + ' ' + @non_clu
select @i = 1, @keys = ''
select @thiskey = index_col(@tblname, @indid, @i)
while @thiskey <> null
begin
if @i > 1
begin
select @keys = @keys + ", "
end
if ltrim(@keys) is null
select @keys = @thiskey
else
select @keys = @keys + @thiskey
select @sorder = index_colorder(@tblname, @indid, @i)
if (@sorder = "DESC")
select @keys = @keys + " " + @sorder
select @i = @i + 1
select @thiskey = index_col(@tblname, @indid, @i)
end
select @cns_text = @cns_text + ' (' + @keys + ')'
if ltrim(@table_seg) is null begin
select @table_seg = s.name
from sysobjects o, syssegments s, sysindexes i
where o.id = object_id(@tblname)
and i.id = o.id
and i.indid < 2
and i.segment = s.segment
if @@rowcount = 0 begin
print '表%1!所在的段不存在',@tblname
goto err
end
end
if charindex('T',@indextg) <= 0
select @cns_text = 'alter table '+@dbname+@username + '.'+@table_name+' add '+@cns_text+ " on '" + @table_seg + "'"
if @prechar <> '$'
print '%1!%2!',@prechar,@cns_text
select @table_dll = @table_dll + @cns_text
end
if charindex('T',@indextg) > 0 begin
if @prechar <> '$'
print '%1!%2!',@prechar, ') '
select @table_dll = left(@table_dll,char_length(@table_dll)-1) + @CRNW + ')'
--表锁计划
if @sysstat2 & 8192 = 8192
select @lock_scheme = 'lock allpages'
else if @sysstat2 & 16384 = 16384
select @lock_scheme = 'lock datapages'
else if @sysstat2 & 32768 = 32768
select @lock_scheme = 'lock datarows'
select @table_dll = @table_dll + @CRNW + @lock_scheme
if @prechar <> '$'
print '%1!%2!',@prechar, @lock_scheme
select @table_seg = "on '"+ @table_seg+"'"
select @table_dll = @table_dll + @CRNW + @table_seg + @CRNW+'go'+@CRNW
if @prechar <> '$' begin
print '%1!%2!',@prechar, @table_seg
print '%1!go',@prechar
end
end
if ltrim(@prxytx) is not null or @sysstat2 & 1024 = 1024
goto ok
if charindex('T',@indextg) > 0 begin
declare @part_num int,@partition varchar(255)
select @part_num = count(*)
from syspartitions
where id = object_id(@tblname)
if @part_num <> 0 begin
select @partition = 'alter table '+ @username + '.' + @table_name + ' partition '+convert(varchar,@part_num)
select @table_dll = @table_dll + @CRNW + @partition
if @prechar <> '$'
print '%1!%2!',@prechar, @partition
end
end
--select @table_dll as table_dll
-------------------------------------------------------------------------------------
--检查其他索引
declare @idx_seg varchar(32)
if charindex('I',@indextg) > 0 or charindex('J',@indextg) > 0 begin
if exists (select 1 from sysindexes where id = @obj_id and indid <> 0 and
(status2 & 2 <> 2 or charindex('P',@indextg) <= 0 and charindex('J',@indextg) <= 0))
begin
declare cur_idx cursor for
select name, indid, status from sysindexes
where id = @obj_id and indid <> 0 and
(status2 & 2 <> 2 or charindex('P',@indextg) <= 0 and charindex('J',@indextg) <= 0)
-- (status2 & 2 <> 2 or charindex('P',@indextg) <= 0)
open cur_idx
fetch cur_idx into @idx_name, @indid, @status
while @@sqlstatus = 0
begin
if @indid = 1
select @non_clu = 'clustered'
else if @indid > 1
begin
if @status & 16 = 16
select @non_clu = 'clustered'
else
select @non_clu = 'nonclustered'
end
if @status & 2 = 2
select @non_uni = 'unique '
else
select @non_uni = null
select @i = 1,@keys = ''
select @thiskey = index_col(@tblname, @indid, @i)
while @thiskey <> null
begin
if @i > 1
begin
select @keys = @keys + ", "
end
if ltrim(@keys) is null
select @keys = @thiskey
else
select @keys = @keys + @thiskey
select @sorder = index_colorder(@tblname, @indid, @i)
if @sorder = "DESC"
select @keys = @keys + " " + @sorder
select @i = @i + 1
select @thiskey = index_col(@tblname, @indid, @i)
end
if ltrim(@index_seg) is null begin
select @idx_seg = s.name
from syssegments s, sysindexes i
where s.segment = i.segment
and i.id = object_id(@tblname)
and i.indid = @indid
if @@rowcount = 0 begin
print '索引%1!所在的段不存在',@idx_name
goto err
end
end
else
select @idx_seg = @index_seg
if ltrim(@keys) is not null begin
declare @thisidx varchar(500)
select @thisidx = 'create ' + @non_uni
+ @non_clu + ' index ' + @idx_name + ' on ' + @dbname + @username
+ '.' + @table_name + "(" + @keys + ") on '" +@idx_seg+"'"
select @index_dll = @index_dll + @thisidx + @CRNW
if @prechar <> '$'
print '%1!%2!',@prechar, @thisidx
end
fetch cur_idx into @idx_name, @indid, @status
end
if ltrim(@index_dll) is not null begin
if @droptg <> '0' begin
select @index_dll = @index_dll + 'go' + @CRNW
if @prechar <> '$'
print '%1!go',@prechar
end
end
select @table_dll = @table_dll + @CRNW + @index_dll
end
end
ok:
set nocount off
return 0
err:
set nocount off
return -1
end
go
本文出自:冯立彬的博客
相关推荐
Sybase ASE 15.0简体中文技术参考手册.7z
本人从2004年从事这块工作,有些资料很难寻,分享出来共大家学习使用。 SybaseASE15.0 Enhanced Full-Text Search Specialty Data Store.pdf SybaseASE15.0 HA_故障切换.pdf SybaseASE15.0 Historical Server用户指南.pdf SybaseASE15.0 Job Scheduler用户指南.pdf SybaseASE15.0 Monitor Client程序员指南.pdf SybaseASE15.0 Monitor Server用户指南.pdf SybaseASE15.0 Replicator用户指南.pdf SybaseASE15.0 T-SQL用户指南.pdf SybaseASE15.0 WEB服务用户指南.pdf SybaseASE15.0 XML服务.pdf SybaseASE15.0 中的JAVA.pdf SybaseASE15.0 分布式事务管理.pdf SybaseASE15.0 参考手册-表.pdf SybaseASE15.0 参考手册_命令.pdf SybaseASE15.0 参考手册_构件块.pdf SybaseASE15.0 参考手册_过程.pdf SybaseASE15.0 实用程序指南.pdf SybaseASE15.0 快速参考指南.pdf SybaseASE15.0 快速安装指南_Linux.pdf SybaseASE15.0 快速安装指南_Win.pdf SybaseASE15.0 查询处理器.pdf SybaseASE15.0 的新增功能.pdf SybaseASE15.0 系统管理指南_第1券.pdf SybaseASE15.0 系统管理指南_第2券.pdf SybaseASE15.0 组件集成服务用户指南.pdf SybaseASE15.0 词汇表.pdf SybaseASE15.0 迁移指南.pdf SybaseASE15.0 配置指南-UNIX.pdf SybaseASE15.0 配置指南-Win.pdf SybaseASE15.0.2安装指南_Linux.pdf Unified Agent和Agent Management Console用户指南.pdf
Sybase总结
现在项目组使用的数据库是Sybase,之前都是用Oralce的,在熟悉Sybase时发现Sybase的资料还是很少的(尤其网上资料),摸索很长时间后才慢慢适应过来,闲余之时,总结了下SybaseIQ的使用心得,由于之前用的的Oralce,所以有的差异也是和Oralce作的比较。 希望能帮到Sybase初学者。 ==============================...
sybase库中导出全部表的oracle、mysql和sybase的建表语句
sybase库中导出全部表的oracle、mysql和sybase格式的建表语句
SYBASE数据库建表及插数据
SYBASE数据库建表及插数据 一、建表 CREATE TABLE SYBASE表名( T_ID numeric(20) not null, T_BIGINT bigint null, T_UNSIGNED_BIGINT unsigned bigint null, T_DECIMAL decimal(10
在SYBASE中用于生当前数据库中所有表的建表语句的过程
在SYBASE中用于生当前数据库中所有表的建表语句的过程。在系统备份的加上BCP,那是相当的好。
sybase导出建表SQL工具
通过输入sybase本地客户端上配置的服务名,用户名,密码,还是所建的用户,登录进去就可以选择所要导出的表的建表SQL,可以导出所有表的建表sql,将其写入到文件里。
常用Sybase命令
Sybase命令 文章目录Sybase命令数据库配置修改最大连接数为500查询设备数修改设备数为100缺省缓存分配页大小最大锁数配置最大内存数配置最大在线CPU配置启动cpu个数配置最大内存数分配最大存储过程缓存配置高速缓存网络包大小最大打开对象最大索引最大锁数增加网络内存锁内存优化tempdb数据库安装数据库安装的优化应用数据库使用裸设备补丁程序安装 SYBASE 在线帮助数据库配置的优化优化master数据库优化tempdb数据库优化系统参数优化数据库系统属性创建阈值存储过程配置多个阈值索引的优化创建索
Sybase存储过程的建立和使用
Sybase存储过程的建立和使用Sybase存储过程的建立和使用Sybase存储过程的建立和使用
jdbc 生成建表语句_mysql数据库下建表语句
mysql建立数据库报错You have an error in your SQL syntax; check the manual that corresponds to your MySQL se在使用xshell远程连接我的服务器时想创建一个数据库结果执行不对,sql语句如下mysql> create database 'wechatmall';结果出现mysql报错,这个提示很明显是...
SAGA GIS英文版进行地形分析,计算常用的地形因子等
SAGA GIS中文版是一款专业的自动化地球科学分析系统软件。SAGA GIS最新版界面简洁,操作简便,用户使用时输入要分割的影像,选择要计算特征的影像或者波段,设置越大,得到的斑块越大;反之,则越小,点击Okay,得到分割影像图。SAGA GIS中文版主要通过选择适合你影像的格式,加载影像。 SAGA GIS全称是System for Automated Geoscientific Analyses,是一种用于编辑空间数据的地理信息系统(GIS)计算机程序,它是免费的开源软件,SAGA GIS旨在为科学家
Zynq实战:如何用AXI4-Stream To Video Out实现HDMI视频输出(附时序调试技巧)
本文详细介绍了基于Zynq平台使用AXI4-Stream To Video Out IP核实现HDMI视频输出的工程化解决方案。内容涵盖系统架构设计、AXI4-Stream接口优化、异步FIFO配置、时序同步调试技巧等核心环节,特别针对1080p60视频输出提供具体参数配置和性能优化建议,帮助开发者快速构建稳定的视频处理系统。
利用PowerDesigner反向工程sybase建表语句
准备好建表语句(通过center导出、或工具导出建表语句)打开PowerDesigner的菜单 按下面步骤:点击确认就可以生成对应PDM模型。
555时基芯片的5种经典电路设计:从方波发生器到PWM调光实战
本文深入解析了555时基芯片的5种经典电路设计,从基础的无稳态方波发生器、单稳态触发器,到实用的占空比可调PWM信号源,并重点介绍了如何引入TVS保护电路增强系统鲁棒性。最后通过一个带保护的PWM LED调光台灯实战项目,综合展示了信号生成、功率驱动与电路保护的核心技术,是电子爱好者掌握模拟电路设计与应用的绝佳指南。
Sybase生成oracle建表语句
单个表 --单个表 declare @pre varchar(10),@schema varchar(20), @tablename varchar(30), @tablespace varchar(30), @role1 varchar(100), @role2 varchar(100) set @pre ='' set @schema ='' -- set @tablename ='tblMDRT
用Omniverse Kit开发第一个USD插件:从环境配置到实战案例(Python 3.7版)
本文详细介绍了如何使用NVIDIA Omniverse Kit和Python 3.7开发第一个USD插件,涵盖从环境配置到实战案例的全过程。通过创建可实时同步材质属性的USD插件,开发者可以快速掌握Omniverse开发框架,提升3D内容创作效率。
RK3588平台开发系列讲解(项目篇)常见模型结构
📢 AI 模型常采用人工神经网络来模拟人脑神经的记忆和处理信号的能力。常见的人工神经网络类型有深度神经网络(Deep Neural Network,DNN)、卷积神经网络(Convolutional Neural Network,CNN)、循环神经网络(Recurrent Neural Network,RNN)等。
Sybase 生成table创建语句
在sybase中写一个存储过程,获取table的创建语句。 -- [/Formatter] Formatted with Sybase T-SQL Formatter(version: 1.5.1.14696) at 05/22/2019 18:07:46 08:00:00[Formatter/] IF OBJECT_ID('get_create_sql') IS NOT NULL DROP...
零基础实战:用 Docker 和 vLLM 本地部署 BGE-M3 文本嵌入模型
BGE-M3是北京智源推出的多功能文本嵌入模型,支持跨语言语义匹配。利用Docker容器化和vLLM框架可高效部署该模型,实现本地运行的优势包括隐私保护、定制化和成本控制。通过配置Docker环境,使用vLLM官方镜像加载模型,并进行文本嵌入测试验证效果。该方案适合开发者快速验证模型能力,或集成到本地NLP流程中。
424



被折叠的 条评论
为什么被折叠?



