简体   繁体   English

为什么我的表在运行此事务后才设置为只读

[英]Why has my Table been set to read only after running this transaction

桌面上的只读标记的屏幕截图

I ran the transaction below because I wanted to insert values from a table called RoughworkIndirectFlights into a table called RoughworkPriceTable. 我在下面运行了这个事务,因为我想将一个名为RoughworkIndirectFlights的表中的值插入一个名为RoughworkPriceTable的表中。

This transaction did not work . 此交易无效 However after running it the RoughworkPriceTable has become set to Read Only. 但是在运行它之后,RoughworkPriceTable已设置为只读。

Can anyone explain why this has happened and how can I change the table to become editable. 任何人都可以解释为什么会发生这种情况,如何更改表格以使其可编辑。

SET IDENTITY_INSERT dbo.RoughworkPriceTable ON;

    Declare @TransactionName varchar(50) = 'MergeTransaction';
    Begin Tran @TransactionName

    Merge RoughworkPriceTable AS p
    Using RoughworkIndirectFlights As i
    On p.ID = i.ID
    When Matched Then Update 
                      Set p.Airport_ICAO_Code=i.Airport_ICAO_Code,
                          p.Airline_ICAO_Code=i.Airline_ICAO_Code,
                          p.RouteStatus=i.RouteStatus
    When Not Matched By Target Then Insert(ID,Airport_ICAO_Code,Airline_ICAO_Code,RouteStatus)
                                    Values(i.ID,i.Airport_ICAO_Code,i.Airline_ICAO_Code,i.RouteStatus)
                                    Output $action, Inserted.*,Deleted.*;

It seems that only ID column is read-only and I believe that ID column is an Identity column in your table. 似乎只有ID列是只读的,我相信ID列是表中的Identity列。 If that's the case then this behavior is expected. 如果是这种情况,则预期会出现此行为。 As the value of Identity column is auto-incremented and you can't set the value of that, that's why that ID column is read-only. 由于Identity列的值是auto-incremented并且您无法设置其值,因此ID列为只读的原因。 I hope you are able to change the value in other columns. 我希望您能够更改其他列中的值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM