Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the equivalent of 'CREATE TABLE ... LIKE ..." in SQL Server

Tags:

I am working with SQL Server (I am a SQL Server noob) and trying to alter a table. I want to CREATE TABLE LIKE to safely store data while I drop keys and constraints and all the other rigamorole that SQL Server seems to require when altering on the original table but I have not been able to find a match to that command...

like image 959
Ichorus Avatar asked Mar 05 '09 18:03

Ichorus


People also ask

What can I use instead of like in SQL?

You may come across the situation, where you need alternate to “like” keyword of SQL, that is to search for sub-string in columns of the table. The one way to achieve it to use instr() function, instr() function takes 3 parameters in account .

What is CREATE TABLE as SELECT?

The CREATE TABLE AS SELECT (CTAS) statement is one of the most important T-SQL features available. CTAS is a parallel operation that creates a new table based on the output of a SELECT statement. CTAS is the simplest and fastest way to create and insert data into a table with a single command.


1 Answers

you want to recreate the same structure?

how about this

 SELECT *  into test  FROM myRealTable  where 0=1 

no data will be inserted into the new table

like image 154
Fredou Avatar answered Sep 19 '22 06:09

Fredou