0

我有这些桌子。我想写更新查询

   CREATE TABLE [dbo].[Feasibility](
[FeasibilityID] [int] IDENTITY(1,1) NOT NULL,
[orderstatus] [varchar](20) COLLATE SQL_Latin1_General_CP1_CI_AS NULL CONSTRAINT [DF_Feasibility_orderstatus]  DEFAULT ('Not Placed')
     CONSTRAINT [PK_Feasibility] PRIMARY KEY CLUSTERED 
     (
[FeasibilityID] ASC
     )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
     ) ON [PRIMARY]



     CREATE TABLE [dbo].[OrderMaster](
[orderid] [int] IDENTITY(1,1) NOT NULL,
[feasibilityid] [int] NULL,

     CONSTRAINT [PK_OrderMaster] PRIMARY KEY CLUSTERED 
    (
[orderid] ASC
     )WITH (PAD_INDEX  = OFF, IGNORE_DUP_KEY = OFF) ON [PRIMARY]
     ) ON [PRIMARY]

我想将可行性表中的 orderstatus 更新为 ordermaster 表中存在的所有记录的“已关闭”

4

4 回答 4

1

最好有JOIN声明而不是IN. 它会快得多。你可以在下面试试这个

UPDATE F
SET    F.OrderStatus = 'closed'
FROM   Feasibility  AS F
JOIN   OrderMaster AS O
ON     F.FeasibilityID = O.FeasibilityID 
于 2013-07-02T06:12:34.350 回答
0

使用以下查询

update Feasibility set orderstatus='closed' where 
FeasibilityID in (select feasibilityid from OrderMaster)
于 2013-07-02T04:47:45.700 回答
-1

试试这个

update Feasibility set orderstatus='closed' where FeasibilityID in (select FeasibilityID from OrderMaster)
于 2013-07-02T04:48:46.583 回答
-1

试试这个...

  update feasibility set orderstatus='Closed' where feasiablityID in(select distinct          
  feasiablityID from ordermaster)

您应该将关键字区分为高效、快速和少错误的工作............

于 2013-07-02T04:51:25.183 回答