Create Table From Another Table in Sql
Server Or Copy Table Structure
Table From Another Table: In
some situations we need to create
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.
Table from another
Table With Data
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 ())
GetDate() Function returns current date with time.
we have a table with some data now copy columns from base table using INTO
Select * INTO CopyTable From BaseTable where 1 = 2
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
Now let`s check
the existence of our copy table.
This command will copy table
from some another table with its datatype it doesn`t
copy any Constraint (primary key, foreign key etc.)
click the link and choose "Save As.." to download this file.)
Table in Sql Server
With Primary Key
Create Foreign Key in
Sql Server Default
Increment Column in Sql Server
Constraint in Sql Server
Key In Sql Server
Table From Another Table
Table From Another Table With Data In Sql Server
comments powered by
Disqus. comments powered by