动态网站制作指南
[  QQ表情  ]
[ 投票调查 ]
[ 企业邮箱 ]
[ 网站空间 ]
网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
ASP源码 | .Net源码 | PHP源码 | JSP源码 | JAVA源码 | CGI源码 | VB源码 | C++源码 | Delphi源码 | PB源码 | VF源码 | 汇编 | 服务器
电脑书籍下载:程序设计书籍 | 数据库教程书籍 | 平面与多媒体书籍 | 网络通讯书籍 | 系统管理书籍 | 网络安全书籍 | 认证考试书籍
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > 数据库学院 > 数据库技巧
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
数据库:数据库教程,数据库技巧,Oracle教程,MySQL教程,Access教程,DB2教程,数据库安全,数据库文摘
文章搜索服务
邮件订阅
输入你的邮件地址,
你将不会错过任何关于:
[ 数据库技巧 ]的信息

本月文章推荐
.金额阿拉伯数字转换为中文的存储.
.用SQLServer2000索引视图提高性能.
.SQL Prompt:SQL智能完成工具!.
.优化数据库的方法及SQL语句优化的.
."SQL Server不存在或访问被拒绝".
.在数据库中建表时记录长度为什么.
.无法在 SQL Server 2005 Manger .
.同时使用数据库链和序列时的注意.
.Sql Sever数据库自动备份.
.异构数据库之间的导入导出.
.SQL Server2000数据库分离与附加.
.数据库死锁导致网站站点访问不了.
.SQL Server 7.0数据库的六种数据.
.怎样用SQL 2000 生成XML.
.使用程序导出建表语句,及以Inse.
.优化SQL Server服务器内存配置的.
.SQL端口改变后的远程连接和数据库.
.安装Ms SQL Server 2005 开发版时.
.将表数据生成SQL脚本的存储过程.
.sqlplus命令的使用大全.

对系统默认的约束名和索引名进行重命名

文章类别:数据库技巧 | 发表日期:2008-3-3 |


对系统默认的约束名和索引名进行重命名的存储过程示例:


create or replace procedure proc_rename_constraint
as
--查找用户所有表的游标
cursor cur_table is select table_name from user_tables;

--查找某张表所有约束的游标
cursor cur_cons (c_table varchar2) is select
c.constraint_name,c.constraint_type,
c.search_condition from user_constraints c
where c.table_name=c_table
and substr(c.constraint_name,2,2) <> 'K_';

--查找某个约束所有字段的游标
cursor cur_columns(c_cons varchar2) is select
column_name from user_cons_columns
where constraint_name=c_cons;

--存储修改后的约束名
v_new_cons_name varchar2(100);

--存储修改约束名的SQL语句
v_sql varchar2(150);

--存储重名的个数
cnt number :=1;

--存储新索引名的个数
n_idx number;

--存储新约束名的个数
n_con number;

begin
--循环取表名
for cur_ltable in cur_table loop

--循环取约束名
for cur_lcons in cur_cons(cur_ltable.table_name) loop

v_new_cons_name :=null;

--循环取字段名
for cur_lcolumns in cur_columns(cur_lcons.constraint_name) loop
v_new_cons_name := v_new_cons_name || cur_lcolumns.column_name;
end loop;
v_new_cons_name := replace(v_new_cons_name,'_','');
v_new_cons_name := cur_ltable.table_name ||'_' || v_new_cons_name;

if cur_lcons.constraint_type='P' then
v_new_cons_name := 'PK_' || v_new_cons_name;
elsif cur_lcons.constraint_type='R' then
v_new_cons_name := 'FK_' || v_new_cons_name;
elsif cur_lcons.constraint_type='U' then
v_new_cons_name := 'UK_' || v_new_cons_name;
elsif cur_lcons.constraint_type='C'
and instr(cur_lcons.search_condition,'IS NOT NULL') > 0 then
v_new_cons_name := 'CK_' || v_new_cons_name || 'NOTNULL' ;
elsif cur_lcons.constraint_type='C'
and instr(cur_lcons.search_condition,'IS NOT NULL') = 0
and cur_lcons.search_condition is not null then
v_new_cons_name := 'CK_' || v_new_cons_name;
end if;

--约束名如果超过30个字符的处理
if length(v_new_cons_name) > 29 then
v_new_cons_name := substr(v_new_cons_name,1,15)
|| substr(v_new_cons_name,-14);
end if;

--查找系统里是否有新的约束名
select count(*) into n_con from user_constraints
where constraint_name=v_new_cons_name;
select count(*) into n_idx from user_indexes where
index_name=v_new_cons_name;
if n_con > 0 or n_idx > 0 then
v_new_cons_name := v_new_cons_name || to_char(cnt);
cnt := cnt +1;
end if;


--对由主键和唯一键创建的索引进行改名,改后的名字为新的约束名
if cur_lcons.constraint_type='P' or cur_lcons.constraint_type='U' then
select count(*) into n_con from user_indexes where
index_name=cur_lcons.constraint_name;
if n_con = 1 then
v_sql := 'alter index ' || cur_lcons.constraint_name
|| ' rename to ' || v_new_cons_name;
execute immediate v_sql;
end if;
end if;

--对约束改名
v_sql := 'alter table ' || cur_ltable.table_name || ' rename constraint ';
v_sql := v_sql || cur_lcons.constraint_name || ' to ' || v_new_cons_name;
execute immediate v_sql;

end loop;

end loop;

end;


上一篇:SQLServer中需要避免的查询设计错误 人气:708
下一篇:奇怪的SQL:排序方法不同但结果却是一样的 人气:330
点击此处浏览全部索引的内容 Dreamweaver插件下载 常用网页广告代码全集
  最新网站源码 最新软件下载
2008-5-16 乘风多用户PHP统计系统 v3.4
2008-5-16 轩溪下载系统 v3.78 build 0515
2008-5-16 普沙B2B 浙江省商贸网 v2.0
2008-5-16 asp抓蜘蛛的小程序 v1.0
2008-5-16 齐齐乐网私服发布站 仿haosf新版
2008-5-16 IssTech信息反馈系统 v1.0
2008-5-16 自由领域大头贴(js接口版) 修正版
2008-5-16 医院网站系统
2008-5-16 智拓-分类信息管理系统 v5.0
2008-5-7 Windows XP SP3 官方英文版
2008-5-7 Windows XP SP3 官方香港中文版
2008-5-7 Windows XP SP3 官方繁体中文版
2008-5-7 Windows XP SP3 官方简体中文版
2008-4-30 Multiple Unzip Wizard 1.02
2008-4-30 Multiple Unrar Wizard 1.0.0
2008-4-30 WinZip Install/Try/Uninstall a
2008-4-30 ZIP压缩文件修复器WzipFix 2.0
2008-4-30 Pentazip 6.01 Build 189 For Wi
  发表评论
姓 名: 验证码: [ 全部贴吧 ] [ 浏览评论 ]
内 容:
[ 汉字翻译拼音 ] [ 广告代码 ] [ 符号对照表 ] [ 进制转换 ] [ 经典小工具 ] [ 个税计算 ] [ 汉字简繁转换 ] [ 普通单位换算 ] [ 公制单位换算 ]
[ 生辰老黄历 ] [ 国内电话区号 ] [ 国家代码与域名缩写 ] [ 文字加密解密 ] [ 健康查询 ] [ 万年历 ] [ 手机号码查询 ] [ ip搜索 ] [ Google PR查询 ]
业务联系 | 广告刊登 | 频道合作 | 投稿荐稿 | 联系方式 | 加入收藏 | RSS订阅
Copyright © 2000-2008 www.knowsky.com All rights reserved | 网络实名:动态网站制作指南 | 沪ICP备05001343号