开发者

How to GRANT permissions to a SQL role to create and manage temp tables

I'd like to grant permissions to a SQL role to create a temp table #foo and grant permissions to do anything with that table (SELECT, INSERT and DELETE). How is it possible if the table #foo is not created (the user that belongs to this role will create and开发者_如何学C manage it)?

Thanks

NOTE: If possible, the solution should work with both SQL 2008 and SQL Azure.


You can't:

Global temporary tables are automatically dropped when the session that created the table ends and all other tasks have stopped referencing them. The association between a task and a table is maintained only for the life of a single Transact-SQL statement. This means that a global temporary table is dropped at the completion of the last Transact-SQL statement that was actively referencing the table when the creating session ended. link text


I am not sure about Azure, but ...

If you explicitly create a table in the tempdb, it persists across sessions, but will be cleaned out upon server reboot.

create table tempdb..authors (au_id char(11))

If you create a ##TempTable it is globally visible, but it also ends with the creator's session.


Apparently, a user created with AUTHORIZATION dbo will already have a right to create and manage a temp table once he is connected to the database. It is only when this user needs to access other tables in the database, he needs explicit permissions granted to him.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜