If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > PostgreSQL > Create empty table copy

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-10-11, 22:36
yasiru yasiru is offline
Registered User
 
Join Date: Jul 2011
Posts: 2
Create empty table copy

Hi All
I found that following sql will create a copy, but with same sequence table.
CREATE TABLE tablename (LIKE oldtablename INCLUDING DEFAULTS);

But I want to create new empty table copy of existing table with new sequence or copy of existing sequence.

Is anyone know how to create empty table copy of existing table like this.
Reply With Quote
  #2 (permalink)  
Old 07-11-11, 05:32
rski rski is offline
Registered User
 
Join Date: Nov 2006
Posts: 82
Quote:
but with same sequence table.
What is sequence table?
Reply With Quote
  #3 (permalink)  
Old 07-11-11, 11:36
futurity futurity is offline
Registered User
 
Join Date: May 2008
Posts: 270
After you create your new table, you'll have to manually create a new sequence and make that the default value of your column. So unless there are other default column values you're trying to copy, omit WITH DEFAULTS from your statement.
Reply With Quote
  #4 (permalink)  
Old 07-11-11, 19:03
yasiru yasiru is offline
Registered User
 
Join Date: Jul 2011
Posts: 2
Thanks

Thanks futurity!

This is for solution for backup table which contain millions of records. By this I can rename the table and make a new table. Hope it is better to do this way, than copying to a new table.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On