如何在 SQL Server 中使用选择查询创建表? [英] How to create table using select query in SQL Server?

查看:46
本文介绍了如何在 SQL Server 中使用选择查询创建表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I try to make 50-100 tables using SYS queries

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表查询结果创建表?

How to create table from SYS tables queries result?

推荐答案

使用子选择的示例语句:

An example statement that uses a sub-select :

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

注意子查询必须有一个名字..任何名字..例如上面的示例为子查询命名为 mysourcedata.否则,SQL*server 2012 中会出现语法错误.

note that the sub query must be given a name .. any name .. e.g. above example gives the subquery a name of mysourcedata. Without this a syntax error is issued in SQL*server 2012.

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

The database should reply with a message like: (9999 row(s) affected)

这篇关于如何在 SQL Server 中使用选择查询创建表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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