Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create table using select query in SQL Server?

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

How to create table from SYS tables queries result?

like image 704
loki Avatar asked Jun 20 '12 07:06

loki


People also ask

Can I create a table from a query?

On the Design tab, in the Query Type group, click Make Table. The Make Table dialog box appears. In the Table Name box, enter a name for the new table. Click the down-arrow and select an existing table name.

How will you create a table from SELECT query result?

If you would like to create a new table, the first step is to use the CREATE TABLE clause and the name of the new table (in our example: gamer ). Then, use the AS keyword and provide a SELECT statement that selects data for the new table.

How will you create a table using SELECT statement in SQL Server?

SELECT INTO Syntax Copy only some columns into a new table: SELECT column1, column2, column3, ... WHERE condition; The new table will be created with the column-names and types as defined in the old table.


2 Answers

select <column list> into <table name> from <source> where <whereclause> 
like image 143
David Brabant Avatar answered Sep 22 '22 11:09

David Brabant


select <column list> into <dest. table> from <source table>; 

You could do this way.

SELECT windows_release, windows_service_pack_level,         windows_sku, os_language_version into   new_table_name FROM   sys.dm_os_windows_info OPTION (RECOMPILE); 
like image 25
Vishwanath Dalvi Avatar answered Sep 21 '22 11:09

Vishwanath Dalvi