首页 \ 问答 \ 单个SQL Server表上的死锁(deadlock on a single SQL Server table)

单个SQL Server表上的死锁(deadlock on a single SQL Server table)

我正在使用SQL Server 2008 Enterprise。 并使用ADO.Net + C#+。Net 3.5 + ASP.Net作为客户端访问数据库。 当我访问SQL Server 2008表时,我总是从我的C#+ ADO.Net代码调用存储过程。

我在表FooTable上有3个操作。 并且多个连接将按顺序同时执行它们,即执行delete,execute insert然后执行select。 每个语句(删除/插入/选择)都是单存储过程中的单独的单个事务。

我的问题是删除语句是否可能发生死锁? 我的猜测是,如果多个连接在相同的Param1值上运行,是否可能发生死锁?

BTW:对于下面的语句,Param1是表FooTable的列,Param1是另一个表的外键(指另一个表的另一个主键聚簇索引列)。 对于表FooTable,Param1本身没有索引。 FooTable有另一列用作聚簇主键,但不是Param1列。

create PROCEDURE [dbo].[FooProc]    
(  
 @Param1 int 
 ,@Param2 int  
 ,@Param3 int  
)    
AS    

DELETE FooTable WHERE  Param1 = @Param1     

INSERT INTO FooTable    
 (  
 Param1  
 ,Param2  
 ,Param3  
  )    
 VALUES    
 (  
 @Param1  
 ,@Param2  
 ,@Param3  
  )    

DECLARE @ID bigint    
 SET @ID = ISNULL(@@Identity,-1)    
 IF @ID > 0    
 BEGIN    
      SELECT IdentityStr FROM FooTable WHERE ID = @ID 
 END

以下是活动监视器表的外观,

ProcessID System Process Login Database Status Opened transaction Command Application Wait Time Wait Type CPU 
52 No   Foo suspended 0 DELETE .Net SqlClient Data Provider 4882 LCK_M_U 0 
53 No George Foo suspended 2 DELETE .Net SqlClient Data Provider 12332 LCK_M_U 0 
54 No George Foo suspended 2 DELETE .Net SqlClient Data Provider 6505 LCK_M_U 0 
(a lot of rows like the row for process ID 54)  

I am using SQL Server 2008 Enterprise. And using ADO.Net + C# + .Net 3.5 + ASP.Net as client to access database. When I access SQL Server 2008 tables, I always invoke stored procedure from my C# + ADO.Net code.

I have 3 operations on table FooTable. And Multiple connections will execute them at the same time in sequences, i.e. executes delete, the execute insert and then execute select. Each statement (delete/insert/select) is of a separate individual transaction in the single store procedure.

My question is whether it is possible that deadlock will occur on delete statement? My guess is whether it is possible that deadlock occurs if multiple connections are operating on the same Param1 value?

BTW: For the statements below, Param1 is a column of table FooTable, Param1 is a foreign key of another table (refers to another primary key clustered index column of the other table). There is no index on Param1 itself for table FooTable. FooTable has another column which is used as clustered primary key, but not Param1 column.

create PROCEDURE [dbo].[FooProc]    
(  
 @Param1 int 
 ,@Param2 int  
 ,@Param3 int  
)    
AS    

DELETE FooTable WHERE  Param1 = @Param1     

INSERT INTO FooTable    
 (  
 Param1  
 ,Param2  
 ,Param3  
  )    
 VALUES    
 (  
 @Param1  
 ,@Param2  
 ,@Param3  
  )    

DECLARE @ID bigint    
 SET @ID = ISNULL(@@Identity,-1)    
 IF @ID > 0    
 BEGIN    
      SELECT IdentityStr FROM FooTable WHERE ID = @ID 
 END

Here is what the activity monitor table looks like,

ProcessID System Process Login Database Status Opened transaction Command Application Wait Time Wait Type CPU 
52 No   Foo suspended 0 DELETE .Net SqlClient Data Provider 4882 LCK_M_U 0 
53 No George Foo suspended 2 DELETE .Net SqlClient Data Provider 12332 LCK_M_U 0 
54 No George Foo suspended 2 DELETE .Net SqlClient Data Provider 6505 LCK_M_U 0 
(a lot of rows like the row for process ID 54)  

原文:https://stackoverflow.com/questions/3075885
更新时间:2023-06-14 09:06

最满意答案

对于任何可能不知道如何的人。

response = client.add_permission(
    FunctionName='<YOUR_FUNCTION_NAME>',
    StatementId='AlexaFunctionPermission',
    Action='lambda:InvokeFunction',
    Principal='alexa-appkit.amazon.com',)

For anyone who may not know how.

response = client.add_permission(
    FunctionName='<YOUR_FUNCTION_NAME>',
    StatementId='AlexaFunctionPermission',
    Action='lambda:InvokeFunction',
    Principal='alexa-appkit.amazon.com',)

相关问答

更多
  • 您需要将default密钥添加到您的消息负载中,并指定MessageStructure : import json import boto3 message = {"foo": "bar"} client = boto3.client('sns') response = client.publish( TargetArn=arn, Message=json.dumps({'default': json.dumps(message)}), MessageStructure='json ...
  • 这是我通过python导入SNS的方法: import boto sns = boto.connect_sns() 要么 import boto3 client = boto3.client('sns') This is how I import SNS via python: import boto sns = boto.connect_sns() OR import boto3 client = boto3.client('sns')
  • 最近有一个定制化进入了Boto3,这有助于(除其他外)。 它目前在低级别的S3客户端上公开,可以这样使用: s3_client = boto3.client('s3') open('hello.txt').write('Hello, world!') # Upload the file to S3 s3_client.upload_file('hello.txt', 'MyBucket', 'hello-remote.txt') # Download the file from S3 s3_client ...
  • boto3 AWS SDK for Python有一个modify_volume()函数 ,可以修改卷大小,卷类型和IOPS容量: response = client.modify_volume( DryRun=True|False, VolumeId='string', Size=123, VolumeType='standard'|'io1'|'gp2'|'sc1'|'st1', Iops=123 ) 这可以从用Python编写的AWS Lambda函数调用。 ...
  • 我怀疑它列出了所有公开可用的快照,这可能相当多。 最好将其限制为您所有者的快照。 describe-snapshots()函数带有一个可以缩小返回值的OwnerIds参数。 下面是一个来自boto3快照文档的示例,演示了如何在snapshots迭代器上使用过滤器: snapshot_iterator = ec2.snapshots.filter( DryRun=True|False, SnapshotIds=[ 'string', ], OwnerIds=[ ...
  • 对于任何可能不知道如何的人。 response = client.add_permission( FunctionName='', StatementId='AlexaFunctionPermission', Action='lambda:InvokeFunction', Principal='alexa-appkit.amazon.com',) For anyone who may not know how. response = ...
  • 根据CopySnapshot - Amazon Elastic Compute Cloud : CopySnapshot将快照副本发送到您发送HTTP请求到的区域端点 ,例如ec2.us-east-1.amazonaws.com (在AWS CLI中,这是通过--region参数或默认区域您的AWS配置文件)。 因此,应该将copy_snapshot()命令发送到us-east-1 ,并将Source Region设置为us-east-2 。 如果你想移动最近的快照,你可以运行: import boto3 ...
  • 没有称为root的 IAM用户。 根用户实际上与AWS账户相关联。 它完全独立于IAM,它允许创建个人用户。 您不能禁用与root用户关联的访问密钥,但可以从根用户中删除访问密钥 。 delete-access-key文档不太清楚,但它确实引用了能够通过API调用删除密钥。 如果我正确读取它, 则可以删除根键 - 但只能以root用户身份调用该函数 。 这在Lambda函数中是不可能的。 最好的行动方案可能是通过管理控制台删除根密钥 ,然后尝试找到一种方法来监控它(但我怀疑没有可以提供此信息的调用)。 幸运 ...
  • 默认情况下,仅描述正在运行的实例,除非另有说明。 实例可能需要几分钟才能进入运行状态。 您的程序将永远不会睡眠,因为它在前一步骤中失败,其中状态实际上未在第一次迭代中返回。 使用“IncludeAllInstances”这是一个布尔请求参数,当为true时,包括所有实例的运行状况。 如果为false,则仅包括运行实例的运行状况。 默认值为false By default, only running instances are described, unless specified otherwise. It ...
  • 您假设所有实例都至少有一个标记。 在您的情况下,有些实例没有标记导致您的代码失败。 相反,您可以在迭代tags之前检查标记是否存在。 for instance in instances: if instance.tags: for tag in instance.tags: 上面的代码将忽略没有定义标记的实例。 您可以修改代码以满足您的需求。 要验证这一点,您还可以在打印instance-id和instance-type时打印标记。 for instance in instances: p ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)