资源描述:
《sybase中生成所有建表语句的过程》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、SYBASE中生成所有建表语句的过程Sql代码: 1.if exists(select 1 from sysobjects where name = 'sp_gent' and type = 'P') 2. drop procedure sp_gent 3.go 4. 5.create procedure sp_gent 6.@tblname varchar(30) = null, 7.@prechar varchar(4) = null, --$:no print 8.@tabl
2、e_dll varchar(16384) = null out, 9.@dbname varchar(32) = null, 10.@droptg char(1) = '1', 11.@prxytx varchar(255) = null, 12.@replace varchar(20) = null, 13.@tabtype varchar(1) = 'A', --A:所有表;P:代理表;U:用户表 14.@indextg varchar(3) = 'TPI', --T:纯
3、表;P:主键;I:纯索引;J:除主键外的纯索引(和TP使用与I相同,和I同时使用I失效) 15.@table_seg varchar(32) = null, 16.@index_seg varchar(32) = null 17.as 18.begin 19. set nocount on 20. 21. if @tblname is null begin 22. declare @c_tblname varchar(30) 23
4、. declare cur_1 cursor for 24. select name from sysobjects where type = 'U' order by name 25. open cur_1 26. fetch cur_1 into @c_tblname 27. while @@sqlstatus = 0 begin 28. exec sp_gent 29.
5、 @tblname = @c_tblname, 30. @prechar = @prechar, 31. @dbname = @dbname , 32. @droptg = @droptg , 33. @prxytx = @prxytx , 34. @replace = @replace, 35.
6、 @tabtype = @tabtype, --A:所有表;P:代理表;U:用户表 36. @indextg = @indextg, --A:表和索引;T:纯表;I:纯索引 37. @table_seg = @table_seg, 1. @index_seg = @index_seg 2. fetch cur_1 into @c_tblname 3.
7、 end 4. close cur_1 5. deallocate cursor cur_1 6. return 7. end 8. 9. declare @obj_id int 10. declare @sysstat2 int 11. declare @username varchar(30) 12. 13. select @obj_id = id, @sysst
8、at2 = sysstat2 ,@username = user_name(uid) 14. from sysobjects where name = @tblname and type = 'U' 15. if @@rowcount <> 1 16. begin 17. print 'table %1!