CREATE TABLE permission denied in database 'tempdb'

送分小仙女□ 提交于 2019-12-03 22:56:07

My initial guess is you do not have CREATE table rights on this server. Can you please run these set of queries below?


-- get login first 
select suser_name() 
--or 
SELECT SYSTEM_USER

-- Now get the permissions assigned to you by the server administrator 
use tempDB 
GO 

;with getPermissions as ( SELECT * FROM fn_my_permissions (NULL, 'DATABASE') ) 
select permission_name from getPermissions 
where permission_name like 'create%' 
GO

If permission_name column returns 0 rows then it means you do not have CREATE permission on this DB. contact your DBA to grant db_ddladmin for tempDB. However as Andomar noted the temp tables are automatically created in tempDB when pre-appended with #.

I went into the database, security, users, right-click on the user, properties. Membership, checked db_owner.

Use tempdb
GO
Create User MyUserName For Login MyUserName with Default_Schema= [dbo];
go
use tempdb
go
EXEC sp_addrolemember 'db_ddladmin', N'MyUserName'
go

You need db_ddladmin role for the intended user to create a new table. so db_datawriter role wouldn't be enough.

You're trying to create a permanent table in tempdb. That's rather unusual, tempdb is completely wiped out whenever the SQL Server service restarts.

The normal way to create a temporary table is:

create table #TempTable (...

The # makes it a local (connection-specific) temporary table. A global temporary table starts with ##. No special rights are required to create a temporary table this way.

I faced this problem too. Searched for it, most of the answers were of db_owner, checked that too in Security menu item, but it was not being shown. While searching i went to this blog. Ivan Dimitrov's answer gave me a bit hint. My create table query was:

CREATE TABLE [dbo].[Album](
[Id] [int] IDENTITY(1,1) NOT NULL,
[Name] [nvarchar](150) NULL,
[Description] [nvarchar](500) NULL,
[TrackCount] [int] NULL,
[ReleaseYear] [int] NULL,
[Distributor] [nvarchar](500) NULL,
[ImageUrl] [nvarchar](max) NULL,
[CreatedDate] [datetime] NULL,
CONSTRAINT [PK_Album] PRIMARY KEY CLUSTERED 
(
[Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, 
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

I removed the [dbo]. from the query and then ran it, executed successfully. Maybe it is not a complete solution but i managed to work with it somehow.

I'm not sure if this answer will be helpful, but I experienced a similar problem and this is how I solved it. The issue I was experiencing was due to the fact that my 'create table' was defaulting to tempdb and I needed to specify the database name. As others have stated, I checked with my DB access operators to make sure I had create table permissions. Since I had the necessary permissions already, I came up with the solution below.

The following returned the tempdb error:

driver={SQL Server};server=YOUR_SERVER_NAME;trusted_connection=true

Once I included the database name, the code worked fine. Here is the code that worked for me:

driver={SQL Server};server=YOUR_SERVER_NAME;database=YOUR_DATABASE_NAME;trusted_connection=true'

I hope this post is helpful!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!