更改由其他表引用的列的数据类型 [英] Changing datatype of a column, which is referenced by other tables
问题描述
我要更改表B中引用的主键列的数据类型,其由表B引用。模式类似于 -
表A: col1A number,col2A ...)
表B:(col1B number,col2B ...)
col2B - > col1A
我想将col1A的数据类型从number更改为varchar。我想要在表B中反映。有什么简单的方法吗?
-
谢谢。
不,没有简单的方法来做到这一点。假设两个表都包含数据,您需要
- 添加新
VARCHAR2
列到表A - 更新A以将新列设置为
TO_CHAR(col1A)
- 向表B中添加新的VARCHAR2列
- 更新B以将列设置为
TO_CHAR(col2B)
- 删除现有的外键约束
- 删除现有的主键约束
- 删除
col1A
来自A - 删除
col2B
li>在A& C中重命名新列(如果需要) B到col1A
和col2B
- 创建新的主键约束
-
- 创建新的外键约束
显然,这将是一个相当昂贵的操作。 / p>
I want to change the datatype of a primary key column in Table A, which is referenced by Table B. The schema is something like-
Table A: (col1A number, col2A...) Table B: (col1B number, col2B...)
col2B -> col1A
I want to change datatype of col1A from number to varchar. I want that to reflect in Table B also. Is there any simple way to do that?
-- Thanks.
No, there is no simple way to do this. Assuming that both tables have data in them, you'd need to
- Add a new
VARCHAR2
column to table A - Update A to set the new column equal to
TO_CHAR( col1A )
- Add a new 'VARCHAR2` column to table B
- Update B to set the column equal to
TO_CHAR( col2B )
- Drop the existing foreign key constraint
- Drop the existing primary key constraint
- Drop
col1A
from A - Drop
col2B
from B - Rename the new columns (if desired) in A & B to
col1A
andcol2B
- Create the new primary key constraint
- Create the new foreign key constraint
Obviously, that's going to be a rather expensive operation.
这篇关于更改由其他表引用的列的数据类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!