A VERY specific request this morning:
I want to generate scripts for all the tables available in schema.
I want to generate separate scripts for each table available in schema and each script must contains it’s dependent objects like indexes for that table or if triggers are available the this must include in the script.
I am using SQL developer 4.0.12 version. I tried with export option but separate scripts are generating for index,triggers,tables etc.
To get this exact formatting, we’re going to take advantage of a new option in the Data Modeler extension that’s available in Oracle SQL Developer:
Once you import the data dictionary, you have a lot of control over exactly how the DDL is generated – and we can generate it very quickly as it’s now in the model instead of being queried/generated from the database.
Import the Data Dictionary
Do this, and walk the wizard.
If you need some pointers, here’s a step-by-step post.
Generate the DDL
First, make sure you have the Physical Model open. This will ensure you get things like your storage parameters, triggers, etc.
Then, hit this button:
Make sure you have all of the objects selected, and then toggle the multiple files option. Then pick your output directory and go.
When you’re done, you’ll have something like this:
And if we open one of the table scripts:
CREATE TABLE HR.BEER ( BREWERY VARCHAR2 (100 BYTE) DEFAULT 'NOTBUD' NOT NULL , CITY VARCHAR2 (100 BYTE) , STATE VARCHAR2 (100 BYTE) , COUNTRY VARCHAR2 (100 BYTE) , ID NUMBER NOT NULL ) ; COMMENT ON TABLE HR.BEER IS 'Breweries of the world' ; COMMENT ON COLUMN HR.BEER.BREWERY IS 'Company name, appears on beer labels, often not as funny as they think they are' ; COMMENT ON COLUMN HR.BEER.CITY IS 'Corporate HQ' ; COMMENT ON COLUMN HR.BEER.STATE IS 'State or Province Corporate HQ' ; COMMENT ON COLUMN HR.BEER.COUNTRY IS 'Corporate HQ' ; COMMENT ON COLUMN HR.BEER.ID IS 'Generated by Sequence' ; CREATE INDEX HR.INDEX1 ON HR.BEER ( STATE ASC ) ; CREATE INDEX HR.BEER_COUNTRIES ON HR.BEER ( COUNTRY ASC ) ; CREATE UNIQUE INDEX HR.BEER_PK ON HR.BEER ( ID ASC ) ; ALTER TABLE HR.BEER ADD CONSTRAINT BEER_PK PRIMARY KEY ( ID ) ;
And there you go. As your database is updated, you can merge the updates into your model by using the compare feature.