TutorialSqlServer.Com

Create In Sql Server

Insert In Sql Server 

 Sql Server Select Basic

 Group By In Sql Server


Where in Sql Server
 

Order By in Sql Server
 

Disclaimer 

Author G+ 

 

 

 

Create Table From Another Table in Sql Server Or Copy Table Structure

Create Table From Another Table: In some situations we need to create table from another table for many reasons like we are going to make some changes in the table and we want to keep the schema or just want a look a like table where we can put some data as backup later on or any other reasons.


Create Table from another Table With Data

Obviously to copy a table`s structure you should have a existing table so let`s create a table and put some data.

  
Create
Table BaseTable (Id Int , Name Varchar(50), CreatedOn Datetime )

Insert into BaseTable Values (1 , 'Neeraj Prasad Sharma' , GETDATE())

Insert into BaseTable Values (2 , 'Vikas Kumar' , GETDATE())

Insert into BaseTable Values (2 , 'Mark Wizz' , GETDATE())
          
 

  • Please note: GetDate() Function returns current date with time.




Now we have a table with some data now copy columns from base table using INTO


   
Select
* INTO CopyTable From BaseTable where 1=2
 

  • Please note the where condition we just pass a false statement, can pass any false statement here like 'a'='b' or '2=0 etc.


Copy table in sql server

Create Table From Another table using into command



Now let`s check the existence of our copy table.

  
select
*From CopyTable
      

 

Selecting new copied table in Sql Server

This command will copy table from some another table with its datatype it doesn`t copy any Constraint (primary key, foreign key etc.)

      

Download Script Used

(Right click the link and choose "Save As.." to download this file.)

Comment Below :

      Related Topics:

  1. Create Table in Sql Server

  2. Create Table With Primary Key

  3. Create Foreign Key in Sql Server

  4. Sql Server Default Value

  5. Create Auto Increment Column in Sql Server

  6. Check Constraint in Sql Server

  7. Unique Key In Sql Server

  8. Create Table From Another Table

  9. Create Table From Another Table With Data In Sql Server

 

comments powered by Disqus