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 > DB2 > Create table like & Insert into

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-20-10, 18:53
db2maf db2maf is offline
Registered User
 
Join Date: Sep 2010
Location: Australia
Posts: 7
Create table like & Insert into

Hi Folks,

New to this site.
My system: DB2 v9.5_FP0 (Windows).

I have two questions that I seek help with:

1. I want to create a table using the following:
- db2 create table SCHEMA.DBCFG like SYSIBMADM.DBCFG
however, I want to add a 'snapshot_timestamp' column. Is it possible to achieve that with the create command above or do I have to perform an 'alter table' post the 'create like' command.

2. Having created the table in step 1. above I want to perform inserts using the following command with the inclusion of 'snapshot_timestamp':
insert into SCHEMA.DBCFG select * from sysibmadm.dbcfg
(I'm not sure how to insert the timestamp with this command).

Look forward to your responses,
Thanking you in advance.
Reply With Quote
  #2 (permalink)  
Old 09-20-10, 19:42
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
I was able to insert using:

db2 "create table dbcfg like SYSIBMADM.DBCFG"
db2 "alter table dbcfg add column timestamp timestamp default"
db2 "insert into dbcfg (NAME,VALUE,VALUE_FLAGS,DEFERRED_VALUE,DEFERRED_VA LUE_FLAGS,DATATYPE,DBPARTITIONNUM) select * from SYSIBMADM.DBCFG"


But there must be an easier way to do this.
Reply With Quote
  #3 (permalink)  
Old 09-20-10, 21:24
db2maf db2maf is offline
Registered User
 
Join Date: Sep 2010
Location: Australia
Posts: 7
Thanks Bella and yes there must be an easier way to achieve this.

Mark.
Reply With Quote
  #4 (permalink)  
Old 09-21-10, 08:28
ARWinner ARWinner is offline
Registered User
 
Join Date: Jan 2003
Posts: 3,575
You will have to do the create/alter table steps, I do not see a way around that. But the insert statement can be like this:

Code:
insert into dbcfg select d.*,current timestamp from sysibmadm.dbcfg as d

Andy
Reply With Quote
  #5 (permalink)  
Old 09-21-10, 09:03
db2girl db2girl is offline
∞∞∞∞∞∞
 
Join Date: Aug 2008
Location: Toronto, Canada
Posts: 1,816
Quote:
Originally Posted by ARWinner View Post
insert into dbcfg select d.*,current timestamp from sysibmadm.dbcfg as d
I like this one.
Reply With Quote
  #6 (permalink)  
Old 09-21-10, 10:06
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,193
Please try:
Code:
CREATE TABLE db2admin.dbcfg 
AS (
SELECT dc.*
     , CURRENT_TIMESTAMP AS snapshot_timestamp
 FROM  sysibmadm.dbcfg dc
)
WITH NO DATA
;

INSERT INTO db2admin.dbcfg
SELECT dc.*
     , CURRENT_TIMESTAMP  AS snapshot_timestamp
 FROM  sysibmadm.dbcfg dc
;

Rationale follows...

1) According to the manual "DB2 Version 9.5 for Linux, UNIX, and Windows SQL Reference, Volume 2 Updated March, 2008",
"as-result-table" option was supported by DB2 9.5.

Syntax:

CREATE TABLE table-name as-result-table ...

as-result-table:
[(column-name [, column-name ...])] AS ( fullselect ) WITH NO DATA

2) But, you are using FP0.
Quote:
My system: DB2 v9.5_FP0 (Windows).
So, I don't know you can use that option or not.
Reply With Quote
  #7 (permalink)  
Old 09-21-10, 17:36
db2maf db2maf is offline
Registered User
 
Join Date: Sep 2010
Location: Australia
Posts: 7
Dear all,

Thank you for your ideas. You have resolved my issues and given me options to work with.

Much appreciated.
Mark.
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