我可以为 table 指定锁定 -schema- 还是取决于事务?

Can I specify locking -schema- for a table or it depends on the transaction?

在 Sybase 中,我可以为 table 指定锁定模式(如果是)、数据行、页面或 table 锁。 下面是 SYBASE 中的示例,如何创建 table 并指定锁 table。

create  table dbo.EX_EMPLOYEE(
   TEXT   varchar(1000)  null
)
alter table EX_EMPLOYEE lock allpages
go

在SQL服务器中有这样的lock tables(SO answer)但是我可以为table指定锁吗?

我的问题:我可以指定 table 类型的锁吗?或者在 SQL 服务器中是不同的?是否取决于我运行?

的查询

在这个 link 中说:

As Andreas pointed out there is no default locking level locks are taken as per operation you are trying to perform in the database. Just some examples. If it is delete/update for a particular row exclusive lock will be taken on that row If it is select operation Shared lock will be taken If it is altered table Schema Mod lock will be taken soon and so forth As Jeremy pointed out If you are looking for Isolation level it is read committed.

他们是对的吗?我可以说在 Sybase 中锁定 table 与 SQL 服务器不同吗?

锁定机制不同,但您在 SQL 服务器中确实可以控制锁定 - 您可以指定 with rowlockwith paglockwith (tablockx)获取独占 table 锁的查询示例。

当您控制所有此类锁时 - 您必须对可能造成的阻塞负责 - 因此请谨慎使用。

具有完整描述的文档:https://docs.microsoft.com/en-us/sql/t-sql/queries/hints-transact-sql-table