Sunday, April 29, 2012

How to make or copy new table structure from existing table structure?

There might be quite few times, when you have a view. And you want to create a new table out of existing view without spending more than 1 minute. Or may be you want to create a new table structure out of existing table structure.

Following SQL query can be used to achieve this effect-

select * into new_table_name from old_table_name

Note:- this would not only copy the existing table structure but it would also copy the data present inside existing table.

Good Points:
  1. This is the fastest way to create a new table from scratch, but from existing table.
  2. You can create a new table from existing view.
  3. In above query you can opt to select particular columns or can give new names to existing columns.
Known to work with (As I'm come across different database I would keep on adding different DB's name.):
  1. Sybase

No comments:

Post a Comment