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 > Data Access, Manipulation & Batch Languages > Perl and the DBI > How to extract DDL for Altered tables from .sql file

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-30-08, 21:22
g_newcomer g_newcomer is offline
Registered User
 
Join Date: Apr 2008
Location: CA
Posts: 1
How to extract DDL for Altered tables from .sql file

Hi Experts!

Please help with the task:
A text file .sql contains DDL including 'create table', 'alter table', 'create index', 'drop table' and so on.
I am only interested in DDL for tables that have been altered, the example of the DDL I would like to extract:

alter table A add
ID numeric(22, 7)
;
commit
;
create index A_S on A
(ID) PCTFREE 30 ALLOW REVERSE SCANS
;
commit
;

alter table A add
NAME vargraphic(100)
;
commit
;
create index A_N on A
(NAME) PCTFREE 30 ALLOW REVERSE SCANS
;
commit
;


OS - Windows, using UNIX utilities for Windows (sed, gawk, grep...).

Steps:
1) find table names: grep "alter table" .sql >> tables_list.log

tables_list.log example:
A
A
B
C
D
D
D
D
...

2) using Windows 'for' loop to loop through tables_list.log and pass each table name into 'sed'

for /F %a in (tables_list.log) do sed -n "/%a/, /;/p" .sql >>1.log

The result 1.log is incorrect, it contains duplicates for some, but not for all 'alter table' statements.
Therefore, running 'uniq -u 1.log' and eliminating duplicates is not an option, because source file .sql contains multiple 'alter table A' statements.

Can someone tell where is the problem - incorrect 'sed' or Windows 'for' loop or both?

If this task can be done in Perl, please help a newcomer.


Thanks.
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