Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL server unable to create table in database because of permissions

I am using SQL server 2008 Express R2. I was trying to test a couple of queries when i started getting this error:

  Msg 2760, Level 16, State 1, Line 2
    The specified schema name "t_one" either does not exist or you do not have permission to use it.

SQL:

  CREATE TABLE t_one.clients
(
t_id int NOT NULL PRIMARY KEY IDENTITY,
colOne varchar(255) NOT NULL,
colTwo varchar(255) NOT NULL,
colThree varchar(255) NOT NULL,
colFour varchar(255) NOT NULL,
CONSTRAINT pk_testID PRIMARY KEY(t_id)

)

I granted permissions to my user profile just using the interface and after i clicked OK/save it didn't apply them - when I went back to the permissions for my user they were all unchecked again.

like image 471
jn025 Avatar asked Feb 16 '14 11:02

jn025


People also ask

How do I fix create database permission denied in database Master in SQL Server?

Step 2: Right click “Login” and select the user account under which you want to create the database. Step 3: Right click and select properties tab. Step 4: Under “Server Roles” tab, select “dbcreator” checkbox. Step 5: Click “OK” and try to create database in the user account.

How do I grant permissions to SQL database?

Right-click a stored procedure and select Properties. In the Stored Procedure Properties -stored_procedure_name dialog box, under select a page, select Permissions. Use this page to add users or roles to the stored procedure and specify the permissions those users or roles have.

How do I give SQL Server full permission to database?

Right-click on Logins and select New. Enter the username. To set permissions, double-click the user account and do one of the following: If you are using SQL Authentication, enter the user name.


2 Answers

Try to run it this way:

CREATE SCHEMA t_one
CREATE TABLE t_one.clients
(
t_id int NOT NULL PRIMARY KEY IDENTITY,
colOne varchar(255) NOT NULL,
colTwo varchar(255) NOT NULL,
colThree varchar(255) NOT NULL,
colFour varchar(255) NOT NULL,
CONSTRAINT pk_testID PRIMARY KEY(t_id)

)
like image 62
Roman Pokrovskij Avatar answered Sep 22 '22 12:09

Roman Pokrovskij


To check and create if the schema does not exist, you can have the following running in a separate batch

IF NOT EXISTS ( SELECT  *
                FROM    sys.schemas
                WHERE   name = N't_one' ) 
    EXEC('CREATE SCHEMA [t_one] AUTHORIZATION [dbo]');
GO
like image 27
user919426 Avatar answered Sep 22 '22 12:09

user919426