sql - Get all tables creation scripts from Oracle database -
i have oracle db lot of tables , lot of properties like: primary key,unique key, foreign key,indexes, privileges , partitions.
i need create same tables same properties in new oracle db. there way generate single creation script tables in database?
thanks
yes. can execute below query , content in 'definition' column clob contains ddl corresponding object
select object_type, object_name, dbms_metadata.get_ddl(object_type, object_name) definition dba_objects owner = 'owner_name' , object_type in ('function', 'package', 'procedure', 'sequence', 'table', 'trigger', 'view') order object_type, object_name
below quick vb script helps extract clobs
folder = "folder_name" connstr="<your connection string here>" if fetchfromdb=true set c=createobject("adodb.connection") c.connectionstring=connstr c.open set r=createobject("adodb.recordset") sql="select object_type, object_name, dbms_metadata.get_ddl(object_type,object_name) definition dba_objects owner='<owner_name_here>' , object_type in ('function', 'package', 'procedure', 'sequence', 'table', 'trigger', 'view') order object_type, object_name" r.open sql,c,3,1 dim fs,f set fs=createobject("scripting.filesystemobject") until r.eof set f=fs.opentextfile(folder & "\\" & r("object_type") & "_" & r("object_name") & ".sql",8,true) f.writeline r("definition") r.movenext f.close loop r.close end if
Comments
Post a Comment