44

我尝试使用 SYS 查询创建 50-100 个表

SELECT windows_release, windows_service_pack_level, 
       windows_sku, os_language_version
FROM sys.dm_os_windows_info OPTION (RECOMPILE);     -- DEĞİŞİRSE INSERT ETSIN AYNI ISE DEĞİŞMESİN

-- Gives you major OS version, Service Pack, Edition, and language info for the operating system

-- SQL Server Services information (SQL Server 2008 R2 SP1 or greater)
SELECT servicename, startup_type_desc, status_desc, 
last_startup_time, service_account, is_clustered, cluster_nodename
FROM sys.dm_server_services OPTION (RECOMPILE);


-- Hardware information from SQL Server 2008 
-- (Cannot distinguish between HT and multi-core)
SELECT cpu_count AS [Logical CPU Count], hyperthread_ratio AS [Hyperthread Ratio],
cpu_count/hyperthread_ratio AS [Physical CPU Count], 
physical_memory_in_bytes/1048576 AS [Physical Memory (MB)], 
sqlserver_start_time --, affinity_type_desc -- (affinity_type_desc is only in 2008 R2)
FROM sys.dm_os_sys_info OPTION (RECOMPILE);

如何从 SYS 表查询结果创建表?

4

4 回答 4

77
select <column list> into <table name> from <source> where <whereclause>
于 2012-06-20T07:07:21.190 回答
14
select <column list> into <dest. table> from <source table>;

你可以这样做。

SELECT windows_release, windows_service_pack_level, 
       windows_sku, os_language_version
into   new_table_name
FROM   sys.dm_os_windows_info OPTION (RECOMPILE);
于 2012-06-20T07:08:13.707 回答
11

使用 sub-select 的示例语句:

select * into MyNewTable
from
(
select 
  * 
from 
[SomeOtherTablename]
where 
  EventStartDatetime >= '01/JAN/2018' 
)
) mysourcedata
;

请注意,必须为子查询指定名称.. 任何名称.. 例如,上面的示例为子查询指定了 mysourcedata 的名称。如果没有这个,SQL*server 2012 中就会出现语法错误。

数据库应回复如下消息:(9999 行受影响)

于 2019-02-14T22:41:15.387 回答
0

或者,

您可以使用导入数据(您需要 dba 权限)

您要在其上创建表的数据库名称 -> 鼠标右键单击 -> 任务 -> 导入数据 -> 源和目标信息 -> 编写查询(第二个选项) -> 粘贴您的查询。

这将在目标上创建一个表

于 2021-12-17T14:31:40.430 回答