T-SQL: ¿Cómo se puede crear una tabla con SELECT?
En oracle, puede emitir:
create table foo as select * from bar;
¿Cuál es la sentencia T-SQL equivalente?
24
3 answers
Puede utilizar SELECT INTO
. De MSDN:
La instrucción SELECT INTO crea una nueva tabla y la rellena con el conjunto de resultados de la instrucción SELECT. SELECCIONAR EN se puede utilizar para combine datos de varias tablas o vistas en una tabla. También puede para crear una nueva tabla que contenga datos seleccionados de un servidor vinculado.
Así que:
SELECT col1, col2, col3 INTO newTable FROM existingTable;
36
Author: Oded,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-21 13:26:43
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-21 13:26:43
Puedes probar así:
select * into foo from bar
28
Author: CaffGeek,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-21 13:27:13
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-21 13:27:13
Si quieres escribir en tempdb
Select *
INTO #tmp
From bar
O a una base de datos SQL
Select *
INTO Temp
From bar
4
Author: scarpacci,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-21 13:27:27
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-07-21 13:27:27