由于权限,SQL Server 无法在数据库中创建表

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21810638/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 01:04:52  来源:igfitidea点击:

SQL server unable to create table in database because of permissions

sqlsql-serversql-server-2008

提问by joe

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

我正在使用 SQL Server 2008 Express R2。当我开始收到此错误时,我试图测试几个查询:

  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.

我仅使用界面授予了我的用户配置文件的权限,在我单击确定/保存后,它没有应用它们 - 当我返回到我的用户的权限时,它们都再次未选中。

回答by Roman Pokrovskij

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)

)

回答by user919426

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

回答by jophab

  1. To check whether the schema exists or not, try
  1. 要检查模式是否存在,请尝试

SELECT * FROM sys.schemas WHERE name = 't_one'

SELECT * FROM sys.schemas WHERE name = 't_one'

  1. If the schema t_onenot exist, try running
  1. 如果架构t_one不存在,请尝试运行

CREATE SCHEMA t_one

CREATE SCHEMA t_one

  1. If you don't have permission to create Schema,
  1. 如果您没有创建 Schema 的权限,

USE <database_name>;GRANT CREATE SCHEMA TO <user_name>;GO

USE <database_name>;GRANT CREATE SCHEMA TO <user_name>;GO

Then create schema and run the code for creating the table.

然后创建模式并运行用于创建表的代码。

  1. In the case you have the schema and you are not having the permission to use it,

    USE <database_name>;GRANT CREATE TABLE TO <user_name>;GO

  1. 如果您拥有架构但没有使用它的权限,

    USE <database_name>;GRANT CREATE TABLE TO <user_name>;GO

Then run the code to create table.

然后运行代码来创建表。

Read Docs here

在此处阅读文档