直接在 user_constraint 表中重命名 Oracle 约束有问题吗?
使用 Oracle 10g,我需要重命名一堆 FK 约束,这些约束全部以 LITE 结尾,以包含 FK 前缀。
我的想法是(我已确保所有名称都足够短以容纳前缀):
DECLARE
v_name VARCHAR2(30 BYTE);
v_new_name VARCHAR2(30 BYTE);
CURSOR c1 is select CONSTRAINT name from user_constraints where constraint_type = 'R' and constraint_name like '%_LITE';
BEGIN
OPEN c1;
LOOP
FETCH c1 into v_name;
EXIT when c1%NOTFOUND;
v_new_name:= 'FK_' || v_name;
update user_constraints SET constraint_name = v_new_name where constraint_name = v_name;
END LOOP;
close c1;
END;
有什么原因会导致不安全,而我应该创建 alter table 语句呢?
Using Oracle 10g, I need to rename a bunch of FK constraints which all end in LITE to include an FK prefix.
My thinking was (I've ensured all names are short enough to accommodate the prefix):
DECLARE
v_name VARCHAR2(30 BYTE);
v_new_name VARCHAR2(30 BYTE);
CURSOR c1 is select CONSTRAINT name from user_constraints where constraint_type = 'R' and constraint_name like '%_LITE';
BEGIN
OPEN c1;
LOOP
FETCH c1 into v_name;
EXIT when c1%NOTFOUND;
v_new_name:= 'FK_' || v_name;
update user_constraints SET constraint_name = v_new_name where constraint_name = v_name;
END LOOP;
close c1;
END;
Any reason why that would be unsafe and I should have to create alter table statements instead?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
USER_CONSTRAINTS
是一个视图,您无法以普通用户身份更新它。编辑:即使 SYS 也无法做到这一点,并且对数据字典进行更新对我来说似乎是一个非常糟糕的主意。更好地使用 ALTER TABLE xxx RENAME CONSTRAINT yyy 至 zzz;
USER_CONSTRAINTS
is a view, you cannot update it as a normal user. EDIT: Even SYS cannot do that, and doing updates on the data dictionary seems like an incredibly bad idea to me.Better use ALTER TABLE xxx RENAME CONSTRAINT yyy TO zzz;
正如 ammoQ 所说,别想这样做!这是使用 ALTER TABLE 的等效代码:
As ammoQ says, don't even think about doing that! This is the equivalent code using ALTER TABLE: