除了 SA 之外,谁能指出我需要的正确文档或其他权限来执行以下操作?
当我运行它时,我收到以下错误:
找不到对象“#test”,因为它不存在或您没有权限。
IF NOT EXISTS
(
SELECT
name
FROM sys.server_principals
WHERE
name = 'testlimiteduser'
)
BEGIN
CREATE LOGIN [testlimiteduser] WITH PASSWORD=N'apassword', DEFAULT_DATABASE=[tempdb], CHECK_EXPIRATION=OFF, CHECK_POLICY=OFF
END
IF NOT EXISTS
(
SELECT
name
FROM sys.database_principals
WHERE
name = 'testlimiteduser'
)
BEGIN
CREATE USER [testlimiteduser] FOR LOGIN [testlimiteduser] WITH DEFAULT_SCHEMA=[dbo]
END
IF NOT EXISTS
(
SELECT 1
FROM sys.database_principals AS p
WHERE
p.name like 'testlimiteduser_app'
)
BEGIN
CREATE ROLE testlimiteduser_app
GRANT EXECUTE TO testlimiteduser_app
ALTER ROLE [db_datareader] ADD MEMBER testlimiteduser_app
ALTER ROLE [db_datawriter] ADD MEMBER testlimiteduser_app
ALTER ROLE testlimiteduser_app ADD MEMBER [testlimiteduser]
ALTER ROLE db_owner ADD MEMBER testlimiteduser -- https://learn.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-updateusage-transact-sql?view=sql-server-2017 says db_owner or SA
END
GO
exec as user='testlimiteduser'
drop table if exists #test
create table #test (id int )
exec('UPDATE STATISTICS #test WITH ROWCOUNT = 1000000')
select * from #test
revert;
检查https://learn.microsoft.com/en-us/sql/t-sql/database-console-commands/dbcc-updateusage-transact-sql?view=sql-server-2017中的文档说 db_owner 或 SA 是很好,但它甚至没有出现在我的测试中 db_owner 工作。