Data Definition Language (DDL) is used to create our database objects. You may need to get this DDL code for an object you’ve lost the ‘source code’ for, or perhaps you want to build an script to create something you’ve been putting together with the GUI.
So we have our table, but how would we get the DDL code?
In today’s post, I’ll demonstrate all the different way to accomplish this task using SQL Developer Web. It’ SQL Developer, but in your browser!
So let’s start with an object, in this case my NETFLIX table.
Let’s use code to generate code!
Use the DDL command in the SQL worksheet
Try this with one of your tables.
SET DDL / SHOW DDL – those are SQLcl settings that work across all of our tools. And the ‘DDL’ command generates DDL for an object.
SET ddl constraints off SET ddl ref_constraints off SET ddl tablespace off SET ddl segment_attributes off ddl NETFLIX
The output is sent to the Script Output panel.
Using the Create/Edit Dialogs
Find your table.
Right click on it.
Choose ‘Edit’
If you were to make any changes to the object, you would see those as DDL changes in the ‘Update’ panel.
Using the Modeler
It’s not JUST for making pretty pictures!
From the Modeler page, simply press this button and wait. It can take a minute or so…
If you want it for just a few objects, the easiest thing to do is build a model diagram, then ask for the DDL for those objects.
So add your objects, I just drag and drop them over.
Then the DDL Preview button gives me this –
If we look into the options –
The Movie
Generating DDL in SQL Developer Web’s Data Modeler
4 Comments
Thanks Jeff, that would be awesome. How best to keep abreast new features as they are implemented into SQLcl?
Subscribe 🙂
Is there any plan to enable DDL for a user?
Often just want to see how a user is created with permissions etc, or to create a similar user.
The dbms_metadata sub programs are already there (e.g get granted_ddl) so shouldn’t be too difficult right? 🙂
Correct, it’s not hard. I’ll add to our list ‘Clone/Create Like’ and ‘DDL’ to the User actions.