如何在SQL Server中使用select查询创建表?

时间:2012-06-20 07:03:51

标签: sql sql-server sql-server-2008

我尝试使用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表创建表查询结果?

3 个答案:

答案 0 :(得分:62)

select <column list> into <table name> from <source> where <whereclause>

答案 1 :(得分:13)

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);

答案 2 :(得分:1)

使用子选择的示例语句:

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

请注意,子查询必须被赋予名称..任何名称..例如上面的示例为子查询指定了mysourcedata的名称。没有此功能,SQL * server 2012中将发出语法错误。

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