Creating a Database in SQL+? - sql

In SQL+, I first connect to the server I have been given;
CONNECT/
Connected.
However, when trying to create a Database I get the following:
CREATE DATABASE Project3;
CREATE DATABASE failed
database already mounted
I've also tried - STARTUP NOMOUNT but only states I have insufficient privileges.
Is there something i'm doing wrong here?

In case this is Oracle you are talking about (Oracles default CLI is called SQL*Plus), this means that a database has already been configured on the server. Oracle only uses a single database per server instance. Inside those databases are schema's, and that is where your database objects will be stored.
See the below quote from: http://docs.oracle.com/cd/B28359_01/server.111/b28301/install.htm#ADMQS002
After you create a database, either during installation or as a standalone
operation, you do not need to create another. Each Oracle instance works
with a single database only. Rather than requiring that you to create
multiple databases to accommodate different applications, Oracle Database
uses a single database, and accommodates multiple applications by enabling
you to separate data into different schemas within the single database.

Related

Identify relationships between multiple databases in SQL

I am working on migrating an application from one server to the other. According to the connection string of this application, it is touching different databases. Meaning a view query in DB1 will touch a table in DB2. So while migrating this application, I constant get to see chain of 'Database unavailable' errors and every time I see such error, I have to migrate that specific database.
I am wondering, since we have ER diagrams to know about relationships between tables in a database, is there any way in SQL server to know the relationships/linkages between different DATABASES in a server? Are there any tool that does this?
Depending on number of databases you have, here would be a somehow quick way you can find that out (number of required search = number of available databases in the server):
Use 'SQL Search' application of Red-get
(https://www.red-gate.com/dynamic/products/sql-development/sql-search/download)
and search for the other database names one after another by selecting
your database of interest. Select all objects.
If you have metadata oriented design (a Stored Procedure looping through the names of different other Stored Procedures / Functions from different databases which are stored in a table as metadata and executing them with a wrapper Stored Procesure), then you will have make use of SQL Locator software (http://www.sqllocator.com/Downloads.html) to search for database names in SQL Table values.
Both of the above software are free.
You need to have SSMS (SQL Server Management Studio) installed to be able to use this application. After installation, ‘SQL Search’ will be directly available in your SSMS as an add-on.
SQL Locator can be directly used by providing the SQL Server name and your SQL Server credential.
Note:- The above steps will help you find out the referenced databases from a certain database within the same SQL Server. If you need to find out databases from Linked Server (I do not believe your question is asking that anyways), then you will have to smartly utilize the same above tools to find the external server reference by searching the external server name.

New database in SQL Server is getting created with tables from another database on the same server

I have SQL Server installed on my machine with a few databases in it. Now I am creating a new database on the same server: Databases -> right click -> New database.
When I open the database it is getting created with tables from another database on the same server! Did any one see this behavior/problem before? Any possible solution?
It is completely normal. New databases are based on system model database which is template for them.
Model database
When a CREATE DATABASE statement is issued, the first part of the database is created by copying in the contents of the model database
Is used as the template for all databases created on the instance of SQL Server. Modifications made to the model database, such as database size, collation, recovery model, and other database options, are applied to any databases created afterward.
Read also about other system databases and their usage model/msdb/tempdb/model/resource
New databases are created as a copy of the model system database.
By default, this database is empty, but there is nothing stopping a user with the proper permissions from adding tables or data to the that database. Indeed, if you want to control how new databases are created such as default compatibility levels, default languages, default function, data types, etc. then you can do so by creating them in the model database.

Use of ReportServer and ReportServerTempDB

I have SQL Server 2008 installed on my machine and also Reporting Services Configuration Manager. When I connect to SQL Server, I found two databases already there.
ReportServer
ReportServerTempDB
I know ReportServer is to store reports, data sources, snapshots, subscriptions, etc. But what is ReportServerTempDB for? Why is it created? Is that necessary (for our use)?
Read the documentaion on report server database
The databases are created together and bound by name. By default, the database names are reportserver and reportservertempdb, respectively.
Report Server Temporary Database
Each report server database uses a related temporary database to store
session and execution data, cached reports, and work tables that are
generated by the report server. Reporting Services does not re-create
the temporary database if it is missing, nor does it repair missing or
modified tables. Although the temporary database does not contain
persistent data, you should back up a copy of the database anyway so
that you can avoid having to re-create it as part of a failure
recovery operation. If you back up the temporary database and
subsequently restore it, you should delete the contents. Generally, it
is safe to delete the contents of the temporary database at any time.
However, you must restart the Report Server Windows service after you
delete the contents. If you delete the temporary database, you can
create a new database, and then run the Catalogtempdb.sql script to
add the table structure. The temporary database must have the same
root name as the primary report server database.

Is it necessary to create tables each time you connect the derby database?

I created a schema and few tables manually using the Eclipse database development perspective. But whenever I try to access the table from code, I get "Schema does not exist" error. However, if I create the tables within my program just before using them, all go well. Do I have to create the tables each time I connect to database? Since, I am testing my code, I have to restart the project multiple times.
Three common reasons for "table does not exist" when you think you've already created the tables:
You are connecting to a different database than you think you were connecting to, and since you specified "create=true" on the Connection URL, Derby quietly created a new empty database for you.
You are using the "in-memory" configuration of Derby, which means that when the database is closed (or your application exits), all the contents of the database disappear.
You are connecting to the database as a different user, and you aren't issuing the SET SCHEMA statement, so you are using the default schema name, which is based on your user name, and so the two schemas are different and have completely different tables, so the table you created doesn't seem to exist when you use the other schema.

Connect a MSSQL created database with PostgreSQL

I use Mac and PostgreSQL is the choice for db management. I can not install MSSQL. There's a db which is created and managed by MSSQL.
I must not copy the entire data via a script, to my database (because of using real time data)
My only option is, connecting that MSSQL created db with PostgreSQL.
Is it possible? If yes, how? Will there be any relevant limitations for my queries?
Thanks.
Additional details:
I'll make selections, calculations, statistically.
I won't modify the existing data.
The feature, which allows you to connect to a different database from within PostgreSQL itself, is called foreign data wrapper.
Here, there is a list of available foreign data wrappers, but mssql is not included. But ODBC is, so (in theory) if you install odbc_fdw, you can access foreign mssql tables in your PostgreSQL instance.
There is also a tds_fdw for SQL Server which uses FreeTDS for the connection rather than ODBC