CREATE TABLE permission denied in database 'tempdb'

后端 未结 6 1109
野的像风
野的像风 2021-02-18 17:45

First time I installed SQL Server Management Studio Express and Visual Studio 2005 on my system. Now I am trying to create table by using below script. But if once I execute I a

相关标签:
6条回答
  • 2021-02-18 18:28

    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!

    0 讨论(0)
  • 2021-02-18 18:30

    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 #.

    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-02-18 18:34

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

    0 讨论(0)
  • 2021-02-18 18:37

    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.

    0 讨论(0)
  • 2021-02-18 18:37

    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.

    0 讨论(0)
提交回复
热议问题