Comparing the DDL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Comparing the DDL
# 1  
Old 01-05-2012
Comparing the DDL

I often times need to compare the DDL's:

Ex : File1 can contain the DDL of two tables (often more than 30 - 40)

Code:
CREATE MULTISET TABLE TEST
(
COLUMN1 CHAR(30) NULL,
COLUMN2 DECIMAL(8,2) NOT NULL,
COLUMN3 INTEGER
)

CREATE MULTISET TABLE TEST1
(
COLUMN4 VARCHAR(30) NULL,
COLUMN5 DECIMAL(8,2) NOT NULL,
COLUMN6 INTEGER
)

File 2 can contain:
Code:
CREATE MULTISET TABLE TEST1
  (
     COLUMN5 DECIMAL(8,2) NOT NULL,
COLUMN4 VARCHAR(30) NULL,
COLUMN6 INTEGER
  )
 
CREATE MULTISET TABLE TEST
(
COLUMN1 CHAR(30) NULL,
COLUMN3 INTEGER
COLUMN2 DECIMAL(8,2)  NULL,
)

The DDL's in the files can be in any order.

we need to compare:
Columnnames, Datatypes and also the Column order

If any of these are not matching we will have to produce a report

saying :

TEST1 COLUMN5 order does not match and so on ..

What is most efficient way of achieving this?

[mod]Use code tags, check your PMs.[/code]

Last edited by zaxxon; 01-05-2012 at 05:24 PM.. Reason: code tags
# 2  
Old 01-05-2012
Confirm if this format is fine for you or not.
Code:
sed 's/^ *//;s/ *$//;s/ +/ /' file1 > newfile1
sed 's/^ *//;s/ *$//;s/ +/ /' file2 > newfile2

awk '/^CREATE/{key=$NF} {print > key "." FILENAME}' new*

for file in *.newfile1
do
  Key=`echo ${file%.*}`
  echo "********  compare the key $Key **********"
  diff $file $Key.newfile2
done


********  compare the key TEST **********
4d3
< COLUMN2 DECIMAL(8,2) NOT NULL,
5a5
> COLUMN2 DECIMAL(8,2)  NULL,
7d6
<
********  compare the key TEST1 **********
3d2
< COLUMN4 VARCHAR(30) NULL,
4a4
> COLUMN4 VARCHAR(30) NULL,
6a7
>

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[Solved] Extracting information from DDL's

Dear Experts, I need your help here. I have lot of teradata DDL's as follows, i want to extract field names , field attributes and NOT NULL information from DDL.Could you please help here. Sample DDL: CREATE MULTISET TABLE APS_CALL_IN_PICKUP_CANCELED ,NO FALLBACK , NO BEFORE... (2 Replies)
Discussion started by: srikanth38
2 Replies

2. Shell Programming and Scripting

Parse through ~21,000 Database DDL statements -- Fastest way to perform search, replace and insert

Hello All: We are looking to search through 2000 files with around 21,000 statements where we have to search, replace and insert a pattern based on the following: 1) Parse through the file and check for CREATE MULTISET TABLE or CREATE SET TABLE statements.....and they always end with ON... (5 Replies)
Discussion started by: madhunk
5 Replies

3. Shell Programming and Scripting

extract DDL - output every match to separate file

Hi, i want to extract the 'CREATE INDEX' or 'CREATE UNIQUE INDEX' statements from a ddl file and output each match to a separate file. i was looking around the net but couldnīt find anything. a possible sed-script could be: sed -n '/CREATE*INDEX*/,/COMMIT/p' filename.ddlbut i couldnīt find out... (11 Replies)
Discussion started by: CactusMoon
11 Replies

4. Shell Programming and Scripting

How to use loop to convert a DML statement into DDL?

Hi Unix Gurus, I am a newb. I am creating a script which will use an input file. This input file can have 1 or more than 1 DML staments like INSERT/DELETE/UPDATE. I have to execute these statements using my script but before execution of these DML statements, I need to check the count for... (17 Replies)
Discussion started by: ustechie
17 Replies

5. Shell Programming and Scripting

Pass a DDL statement to a KSH script

I need to pass a DDL statement into a ksh script & parse the statement. What is the best way to pass a DDL statement into a KSH script. ---------- Post updated at 09:28 AM ---------- Previous update was at 07:35 AM ---------- if the name of the script is test.ksh test.ksh "ALTER TABLE... (12 Replies)
Discussion started by: gayathree
12 Replies

6. Shell Programming and Scripting

Extract table name from DDL

How can I extract table name from the different DDL statement like ALTER TABLE CREATE TABLE etc Basically I have to parse thr the any of the DDL statement and verify if that DDL statement is implemented by DBA or not. how can i do this efficiently in Kornshell scripting. (2 Replies)
Discussion started by: gayathree
2 Replies

7. Shell Programming and Scripting

generating a create ddl from a csv file using awk

Hello, I would greatly appreciate some help on the this I have comma delimited file as follows: csv file -------- TEST1,fld1,VARCHAR2,3,,, TEST1,fld2,DATE,,,, TEST1,fld2,VARCHAR2,51,,, TEST1,fld4,VARCHAR2,2,,, TEST1,fld5,NUMBER,4,0,, TEST1,fld6,VARCHAR2,1,,,... (5 Replies)
Discussion started by: jville
5 Replies

8. Shell Programming and Scripting

comparing

i have a file which has following content: the value of x is : 5 In another file i have: the value of x is : i want when i will compare both file then output should come like the value of x is : 5 need some help (1 Reply)
Discussion started by: Aditya.Gurgaon
1 Replies

9. Shell Programming and Scripting

Help required to parse Oracle imp show=y output to DDL Commands

Hi, I generated an Oracle schema DDL script file using the show=y option of the Oracle import utility but the file that it generates needs a little more formating before we can run this as simple DDL comands to generate the schema at Target using the script file.Here is the simplified output of... (1 Reply)
Discussion started by: rajan_san
1 Replies

10. Shell Programming and Scripting

Comparing two files

Hi I have two files X and Y. I have to compare two files and dispaly the lines which are present in X and not in Y along with the line numbers ex X Y a a b b c g e output Z 3. c Thanks (2 Replies)
Discussion started by: superstar003
2 Replies
Login or Register to Ask a Question