There maybe times when you need to create a new table that uses the same structure as an existing table. I had this situation today, where I was working on a Test table in a database and then I needed to create a new table that would be used in production. And obviously the columns and primary key had to be the same. There are many ways where this could be achieved. One of the ways is to do it manually, which is fine until you are looking at a table that has 20 columns with constraints in almost every other column!
The simpler and faster way to replicate the structure of an existing table would be to use a SQL Query. And by a query I don’t mean a complicated, convoluted query! It is in fact very simple and straightforward.
This is the Query you need to use when you would want to create a new table that has the same structure of an existing table-
Create Table NewTable_Name Like OldTable_Name
Where NewTable_Name is the Name of the New Table
OldTable_Name is the name of the Old Table