問題描述
我有一個 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的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!