在特定文件组下创建表 WHERE 1=2 [英] Create table under a specific FileGroup WHERE 1=2

查看:40
本文介绍了在特定文件组下创建表 WHERE 1=2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 WinForms 应用程序,它根据给定的表格动态创建表格,例如:

I have an WinForms application which creates tables dynamically based on a given table such as:

SELECT * INTO TempTable FROM MyTable WHERE 1=2

我希望使用上述语法在特定的 filegroup 下创建那些 Temp 表.

I want those Temp tables to be created under a specific filegroup though using the above syntax.

在文件组下创建表的语法是:

The syntax to create the table under a filegroup is:

CREATE TABLE [dbo].[TempTable](

            [RECORDID] [numeric](10, 0) NOT NULL,
            --etc etc

) ON [TempFileGroup] TEXTIMAGE_ON [TempFileGroup]

是否可以使用我上面的语法在特定文件组下创建表?

Is it possible to use my syntax above to create the table under the specific filegroup?

推荐答案

我希望使用上述语法在特定文件组下创建这些临时表

SQL Server 2017+ 你可以使用 ON filegroup 语法.

From SQL Server 2017+ you could use ON filegroup syntax.

INTO子句

SELECT...INTO 在默认文件组中创建一个新表,并将查询的结果行插入其中.

SELECT…INTO creates a new table in the default filegroup and inserts the resulting rows from the query into it.

[ INTO new_table ]
[ ON filegroup]

文件组

指定将在其中创建新表的文件组的名称.指定的文件组应该存在于数据库中,否则 SQL Server 引擎会抛出错误.仅从 SQL Server 2017 开始支持此选项.

Specifies the name of the filegroup in which new table will be created. The filegroup specified should exist on the database else the SQL Server engine throws an error. This option is only supported beginning with SQL Server 2017.

来自 MSDN 的示例:

Example from MSDN:

创建一个新表作为另一个表的副本并将其加载到指定的文件组

Creating a new table as a copy of another table and loading it a specified filegroup

ALTER DATABASE [AdventureWorksDW2016] ADD FILEGROUP FG2;
ALTER DATABASE [AdventureWorksDW2016]
ADD FILE
(
NAME='FG2_Data',
FILENAME = '/var/opt/mssql/data/AdventureWorksDW2016_Data1.mdf'
)
TO FILEGROUP FG2;
GO
SELECT *  INTO [dbo].[FactResellerSalesXL] ON FG2 from [dbo].[FactResellerSales]

这篇关于在特定文件组下创建表 WHERE 1=2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆