如何在不同的模式下创建 SQL 表?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1489872/
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
How do I create a SQL table under a different schema?
提问by Matt
This is from SQL Server 2008, ssms
这是来自 SQL Server 2008,ssms
When I create a table, it creates under dbo.
当我创建一个表时,它会在 dbo 下创建。
I would like to create it under a different schema, but when I use the 'New Table' dialog, I can never find the field where to specify this.
我想在不同的模式下创建它,但是当我使用“新表”对话框时,我永远找不到指定它的字段。
回答by adrianbanks
- Right-click on the tables node and choose
New Table...
- With the table designer open, open the properties window (view -> Properties Window).
- You can change the schema that the table will be made in by choosing a schema in the properties window.
- 右键单击表节点并选择
New Table...
- 打开表设计器,打开属性窗口(视图 -> 属性窗口)。
- 您可以通过在属性窗口中选择架构来更改将在其中创建表的架构。
回答by Shaun F
Try running CREATE TABLE [schemaname].[tableName]; GO;
尝试跑步 CREATE TABLE [schemaname].[tableName]; GO;
This assumes the schemaname exists in your database. Please use CREATE SCHEMA [schemaname]
if you need to create a schema as well.
这假设 schemaname 存在于您的数据库中。CREATE SCHEMA [schemaname]
如果您还需要创建架构,请使用。
EDIT: updated to note SQL Server 11.03 requiring this be the only statement in the batch.
编辑:更新以注意 SQL Server 11.03 要求这是批处理中的唯一语句。
回答by Aftab Uddin
create a database schema in SQL Server 2008
1. Navigate to Security > Schemas
2. Right click on Schemas and select New Schema
3. Complete the details in the General tab for the new schema. Like, the schema name is "MySchema" and the schema owner is "Admin".
4. Add users to the schema as required and set their permissions:
5. Add any extended properties (via the Extended Properties tab)
6. Click OK.
Add a Table to the New Schema "MySchema"
1. In Object Explorer, right click on the table name and select "Design":
2. Changing database schema for a table in SQL Server Management Studio
3. From Design view, press F4 to display the Properties window.
4. From the Properties window, change the schema to the desired schema:
5. Close Design View by right clicking the tab and selecting "Close":
6. Closing Design View
7. Click "OK" when prompted to save
8. Your table has now been transferred to the "MySchema" schema.
Refresh the Object Browser view To confirm the changes
Done
在 SQL Server 2008 中创建数据库架构
1. 导航到安全 > 架构
2. 右键单击架构并选择新建架构
3. 在新架构的常规选项卡中完成详细信息。例如,架构名称是“MySchema”,架构所有者是“Admin”。
4. 根据需要将用户添加到架构并设置他们的权限:
5. 添加任何扩展属性(通过扩展属性选项卡)
6. 单击确定。
将表添加到新架构“MySchema”
1. 在对象资源管理器中,右键单击表名并选择“设计”:
2. 在 SQL Server Management Studio 中更改表的数据库架构
3. 在设计视图中,按 F4 以显示属性窗口。
4. 在“属性”窗口中,将架构更改为所需的架构:
5. 通过右键单击选项卡并选择“关闭”来
关闭设计视图:6. 关闭设计视图
7. 在提示保存时单击“确定”
8. 您的表现在已转移到“MySchema”模式。
刷新对象浏览器视图 确认更改
完成
回答by map
Hit F4 and you'll get what you are looking for.
按F4,你会得到你想要的。
回答by Sangram Nandkhile
Shaun F's answer will not work if Schema doesn't exist in the DB. If anyone is looking for way to create schema then just execute following script to create schema.
如果数据库中不存在 Schema,Shaun F 的回答将不起作用。如果有人正在寻找创建模式的方法,那么只需执行以下脚本即可创建模式。
create schema [schema_name]
CREATE TABLE [schema_name].[table_name](
...
) ON [PRIMARY]
While adding new table, go to table design mode and press F4
to open property Window and select the schema from dropdown. Default is dbo
.
添加新表时,进入表设计模式并按下F4
打开属性窗口并从下拉列表中选择模式。默认为dbo
。
You can also change the schema of the current Table using Property window.
您还可以使用属性窗口更改当前表的架构。
Refer:
参考:
回答by Brannon
When I create a table using SSMS 2008, I see 3 panes:
当我使用 SSMS 2008 创建表时,我看到 3 个窗格:
- The column designer
- Column properties
- The table properties
- 专栏设计师
- 列属性
- 表属性
In the table properties pane, there is a field: Schema
which allows you to select the schema.
在表属性窗格中,有一个字段:Schema
它允许您选择架构。