Search code examples
sqloracleoracle-sqldevelopersysdba

Oracle running script


I am using Oracle Sql Developer

I have a huge script that creates tables, indexes, primary key constraints and such.

my DB name is: dbo_other

I logged into this dbo_other as sysdba.

If I run my script then tables do not show up on left panel under 'Tables'

However, if I append the script by adding 'dbo_other.' in front of every table name then the tables show up.

This is very tedious and time consuming.

Is there a way to avoid this? why wont they show up in dbo_other without adding dbo_other. in front of every table name?? When I run the query on the upper right corner the drop down has dbo_other selected!!

I can even do a select * from the table created (but dont see it in left sidebar) Furthermore, I can see the table in pl/sql developer.

Why does oracle sql developer want me to create it with dbo_other.??

Also, is there a way to avoid adding it for each table? maybe something can be done on top of the script so it takes effect on everything that follows?


Solution

  • Why are you logging in to your database using the SYSDBA account? This is very powerful, and it will allow you to do terrible damage to your database if you don't know what you're doing. In a development environment there's a limit to the harm you can do but it's best to get into good habits before doing things in Production.

    The interesting thing about AS SYSDBA is that it overrides the username part of the login: if your OS user has the privileges, you're in. As SYS. Check it out:

    SQL> conn apc
    Enter password:
    Connected.
    SQL> show user
    USER is "APC"
    SQL> conn apc as sysdba
    Enter password:
    Connected.
    SQL> show user
    USER is "SYS"
    SQL>
    

    So, when you ran that script you created all those objects in the SYS schema. Which will prove to be a massive pain in the neck. I hope you have an equal and opposite reversion script.

    To run the script properly, all you need to do is connect as DBO_OTHER (normal - i.e. without SYSDBA or SYSOPER which is the default after all). Your script will create tables in the current schema.

    If you need to create objects in several schemas, you don't need to log out and in again. The schema is distinct from the user and it is possible to switch schema by executing alter session set current schema = WHOEVR;. This is quite a handy trick and I blogged it up some time back. Find out more.

    Note that your user will not acquire any additional privileges by changing the current schema: they will only be able to do what they currently can do. So for something like creating objects in multiple schemas the executing user should be a power user, somebody with CREATE ANY privileges such as a DBA (but still not SYSDBA).