Linked Databases in SQL Developer - oracle-sqldeveloper

I'm using SQL Developer to host some data, but I think my configuration isn't right. Lets say I have a database named DB1 with the tables
DB1
-db1_name
-db1_cities
The problem is when I try to create a new database let say DB2, SQLdeveloper creates the database but it also includes all the tables from DB1 (db1_name,db1_cities). Also if I removed the tables from DB2, the tables also disappear from DB1. How can I change my configuration so this does not happen anymore and each database is independent from each other?
To create a new data base I usually go in the SQL Developer GUI interface to connections, then I click on new Connection and provide the connection name, user name, and password. I leave the connection type to basic and the role to default. The host name as local host, and the default port.

That's happening because you are currently adding a new database connection instead of creating a database.
To create a new database from scratch, take a look at this link, it'll take you through step by step on creating the new database.

Related

How can I obtain the creation date of a DB2 database without connecting to it?

How can I obtain the creation date or time of an IBM's DB2 database without connecting to the specified database first? Solutions like:
select min(create_time) from syscat.tables
and:
db2 list tables for schema SYSIBM
require me to connect to the database first, like:
db2 connect to dbname user userName using password
Is there another way of doing this through a DB2 command instead, so I wouldn't need to connect to the database?
Can db2look command be used for that?
Edit 01: Background Story
Since more than one person asked why do I need to do this and for what reasons, here is the background story.
I have a server with DB2 DBMS where many people and automated scripts are using it to create some databases for temporary tasks and tests. It's never meant to keep the data for long time. However for one reason or another (ex: developer not cleaning after himself or tests stopping forcefully before they can do the clean up) some databases never get dropped and they start to get accumulated till the hard disk is filled out eventually. So The idea of the app is to look up the age of the database and drop it, if it's older than 6 months (for example).

Netbeans 7.4: Creating entity classes (JPA) from java db embedded database

I am using Netbeans 7.4 to build my application. And also, I am using embedded java db. Now, I want to generate my JPA entities from my database from my database.
But, when I
rightclick my package -> New -> Entity classes from database, select my database, Available Tables is not showing up even a single one of the tables inside ANK schema.
One more strange thing I noticed is when I connect my db from Netbeans services tab, two schema options appear. First, APP in bold, second Other schemas. Schema APP don't have any tables. The tables are in ANK schema in Other schemas.
Can anybody tell me where I could have gone wrong?
I don't even know if I should be using java db, or I should go for pretty appealing h2, HSQL or some matured db like mysql.
The Nebeans interface to Derby is a bit tricky.
When creating a new database, only the APP schema is created by default (except for the SYS* schemas).
When you connect to the database without specifying a username, your default schema becomes APP
When connecting as user john, your default schema becomes john, BUT the schema john is NOT created, until you create an SQL object in it.
This means that if you create an initial connection to Derby in Netbeans as user john, you cannot choose john as the schema for the connection in the pull-down menu, because it has not been created yet. If you then choose another schema, create your table, disconnect and then create another connection you will be able to choose john as your schema, and you will find the table you created with the previous connection.
Even though you chose a different schema in the pull-down menu for the first connection, a schema with the same name as the username you connect as is created and set as default before starting to execute the create table statement.

libpq code to create, list and delete databases (C++/VC++, PostgreSQL)

I am new to the PostgreSQL database. What my visual c++ application needs to do is to create multiple tables and add/retrieve data from them.
Each session of my application should create a new and distinct database. I can use the current date and time for a unique database name.
There should also be an option to delete all the databases.
I have worked out how to connect to a database, create tables, and add data to tables. I am not sure how to make a new database for each run or how to retrieve number and name of databases if user want to clear all databases.
Please help.
See the libpq examples in the documentation. The example program shows you how to list databases, and in general how to execute commands against the database. The example code there is trivial to adapt to creating and dropping databases.
Creating a database is a simple CREATE DATABASE SQL statement, same as any other libpq operation. You must connect to a temporary database (usually template1) to issue the CREATE DATABASE, then disconnect and make a new connection to the database you just created.
Rather than creating new databases, consider creating new schema instead. Much less hassle, since all you need to do is change the search_path or prefix your table references, you don't have to disconnect and reconnect to change schemas. See the documentation on schemas.
I question the wisdom of your design, though. It is rarely a good idea for applications to be creating and dropping databases (or tables, except temporary tables) as a normal part of their operation. Maybe if you elaborated on why you want to do this, we can come up with solutions that may be easier and/or perform better than your current approach.

Backup and Restoration of Running Schema In Another Database That Already Have Other Schemas

I have a running database with only one dba (i.e. other than sys, system) "abc". Under this oracle user I have tables, views, sequences, procedures, functions etc. Now I have to copy both the data and schema to another database at another machine that already have a dozen schemas running (one under each separate dba). I have following concerns:
(1) I have to rename the schema at old machine, from "abc" to "pqr" before moving to the new machine.
(2) Inside my procedures and functions, I am using AUTHID CURRENT_USER, therefore have to use "abc." qualifier before name of tables, views, sequences, procedures, functions. When changing schema name, is there some automatic way to change qualifiers too.
(3) In order to copy data, I know only one way, which is to take backup of database of only one user "abc" (i.e. not take backup of sys, system). Then restore that to the new database. Can this in anyway destroy the other schemas or their data.
(4) In my schema, I am creating oracle users with limited rights using a procedure. The new usernames are stored in a Users table. I am also creating database roles and associating users with roles. The rolenames are stored in a Roles table. When migrating to new machine I have to make sure to prefix my users and roles with something unique so I not disturb oracle users created by other schemas.
(5) I know that in the new database, there have to be a new dba user called "pqr". Do I also have to have sysdba privilege. I am not responsible about the whole database at new machine, I am responsible about my schema only. Being a sysdba, can I in anyway hurt other dbas (like dropping them, or changing their schemas). If I not have sysdba privilege, what limitations do I get. I am using OracleText so have to use some built-in packages. I also have to create physical directory on file system in windows. I also have to create, alter (change password), drop roles and users via stored procedures when connected to database using "pqr".
Both old and new database are running on separate dedicated machines. Its windows server 2003 with oracle 10gr1.
The simplest option would be to use the Oracle export utility (classic or DataPump) to take a logical backup of the abc schema in the first database and to import the backup using the Oracle import utility into the new database. If you're using the classic version, you'd use the FROMUSER and TOUSER parameters to specify that you want to import the data into a different schema. If you're using the DataPump version, you'd use the REMAP_SCHEMA parameter. The DataPump version will be more efficient if you have a relatively large amount of data.
Unfortunately, though, there is no way to change explicit schema qualifiers. You'll need to edit the code after you import it or pull the code from your source control system, edit the code, and deploy it to the new database.

web application cannot see tables in new postgresql schema

I moved some tables in my postgresql (8.2) database to a new schema.
at first, my "user" could not see the tables in the new schema, but I used set search_path to tell it to look in this new schema
I access these tables with a simple web application that uses hibernate. At first, my web application, which uses the "user" user, could not see the tables either, even after I set the search_path. I eventually set the default-schema in the hibernate config file and it worked, but I understand from what I've read that I should not have to set this property? I have a few JDBC queries in this app that still can't see the tables in the new schema.
I've browsed through the postgresql docs and can't find the cause of my problems. Is there something simple I'm missing?
SET search_path is not persisted. It is only valid for the current session.
You need to use ALTER USER to make that change permanently, but you don't need special privileges to change the user you are logged in with (i.e. "yourself")