Viewing Scripts in Oracle
Can anyone tell me how I can view scripts to a table that I have created in Oracle along with constraints. I am new to Oracle and I'm unsure how to view them.
Thanks,
Joe
Web Development
Can anyone tell me how I can view scripts to a table that I have created in Oracle along with constraints. I am new to Oracle and I'm unsure how to view them.
Thanks,
Joe
by bill_h
If by "scripts to a table" you mean the SQL command to create the table, you are out of luck *unless* you saved the command. Our standard procedure is to save the command with a .sql extension (i.e., "Make_Tbl.sql") before executing the command. You can easily combine such scripts into a master script should it become necessary to re-create the entire database.
If you neglected to do this, you can retrieve the information and cut-and-paste a script together.
For instance, to get the column information for table "MyTable", use the SQL statement "DESC MyTable". This will display the names of the columns, whether a NULL value is allowed, and the datatype for the column (i.e., VARCHAR2(10), NUMBER(5), etc.)
Info for constraints canbe retrieved using the following tables:
USER_CONSTRAINTS: Shows constraint definitions on a user's own tables.
USER_CONS_COLUMNS: Shows info about the column(s) associated with the user's constraint definitions.
ALL_CONSTRAINTS: Shows all accessible constraint definitions in the database.
ALL_CONS_COLUMNS: Shows info about the column(s) associated with all accessible constraint definitions in the database.
Use the "DESC" command on one of these tables to view the available columns, and then execute a SQL command to retrieve the onfo for the desired constraint, i.e. "SELECT * FROM USER_CONS_COLUMNS WHERE TABLE_NAME = 'MyTable' AND COLUMN_NAME = 'MyTable_PK'".
It's not a very pleasant method, but it will work...besides, once you create the script, you can save it as a .sql file and not have to bother with again, right?
Hope this helps...
by joe.vazquez
Thank you very much Bill.
Joe
by joe.vazquez
This discussion is closed to new replies.
Sort by Trending