如何删除和更新sql中的主键 [英] how to remove and update primary keys in sql
本文介绍了如何删除和更新sql中的主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在从表中删除后添加主键。
I want to add primary key once it is removing from table.
alter table tbl_item_rate alter column c_item_code varchar(25)
此查询正在执行但是错误抛出..
错误ID
this query am executing but error throwing..
error id that
Msg 5074, Level 16, State 1, Line 1
The object 'PK_tbl_item_rate' is dependent on column 'c_item_code'.
Msg 4922, Level 16, State 9, Line 1
ALTER TABLE ALTER COLUMN c_item_code failed because one or more objects access this column.
推荐答案
因为它是主键,所以你无法改变它 - SQL依赖于PK来进行索引。
要更改主键列的类型,你需要删除主键,更改表格,然后重新建立PK:
Because it's the primary key, you can't change it - SQL relies on the PK for it's indexing.
To change the type of teh primary key column, you have to remove teh primary key, change your table, and the re-establish the PK:
ALTER TABLE tbl_item_rate
DROP CONSTRAINT PK_tbl_item_rate
ALTER TABLE tbl_item_rate
ALTER COLUMN c_item_code varchar(25)
ALTER TABLE tbl_item_rate
ADD CONSTRAINT PK_tbl_item_rate PRIMARY KEY (c_item_code)
这篇关于如何删除和更新sql中的主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文