如何改变表格

时间:2009-08-31 06:03:06

标签: foreign-key-relationship

CREATE TABLE [dbo].[INVS_ITEM_LOCATIONS](
    [DEPARTMENT_CODE] [varchar](3) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [IM_INV_NO] [numeric](10, 0) NOT NULL,
    [LOCATION_CODE] [varchar](2) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [CURR_QTY] [numeric](10, 0) NOT NULL CONSTRAINT [DF__INVS_ITEM__CURR___1352D76D]  DEFAULT ((0)),
    [DO_QTY] [numeric](10, 0) NOT NULL CONSTRAINT [DF__INVS_ITEM__DO_QT__1446FBA6]  DEFAULT ((0)),
    [ALLOC_QTY] [numeric](10, 0) NOT NULL CONSTRAINT [DF__INVS_ITEM__ALLOC__153B1FDF]  DEFAULT ((0)),
    [YOB_QTY] [numeric](10, 0) NOT NULL CONSTRAINT [DF__INVS_ITEM__YOB_Q__162F4418]  DEFAULT ((0)),
    [FOC_QTY] [numeric](10, 0) NULL CONSTRAINT [DF__INVS_ITEM__FOC_Q__17236851]  DEFAULT ((0)),
    [USER_CREATED] [varchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL,
    [DATE_CREATED] [datetime] NOT NULL,
    [USER_MODIFIED] [varchar](25) COLLATE SQL_Latin1_General_CP1_CI_AS NULL,
    [DATE_MODIFIED] [datetime] NULL,
 CONSTRAINT [INVS_ITEM_LOCATIONS_PK] PRIMARY KEY CLUSTERED 
(
    [DEPARTMENT_CODE] ASC,
    [IM_INV_NO] ASC,
    [LOCATION_CODE] ASC
)WITH (IGNORE_DUP_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY]

这是我的表名,如何删除im_inv_ni和location_ code

中的主键

我还应该为im_inv_no添加foriegn键....请帮助

1 个答案:

答案 0 :(得分:1)

您可以使用ALTER TABLE -statements。更多信息可以在http://ss64.com/ora/table_a_cons.html找到。

所需的陈述是

ALTER TABLE [dbo].INVS_ITEM_LOCATIONS DROP PRIMARY KEY;
ALTER TABLE [dbo].INVS_ITEM_LOCATIONS ADD CONSTRAINT <name of fk> FOREIGN KEY (<columns>) REFERENCES <table>(<columns>);