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

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.

Related

Creating a Database in 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.

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.

How to copy tables from one db to another? (Sql azure)

Situation:
I have 2 azure database on the same server. All I need is to copy all tables(with data) from one db to another.
How can I make this with query help? I wasn't able to found any answer for it.
I don't think you can do it with query. Check out Import and Export Data program that follows sql management studio. I think it's called DTSWizard.exe. Anyway, it can copy stuff from pretty much any source.
You can use the CREATE DATABASE AS COPY OF command, like this:
CREATE DATABASE destination_database_name AS COPY OF
[source_server_name.]source_database_name
Same-Server Copying
When you copy a database to make a new database on the same SQL Database server, the same logins can be used on both databases. The security principal you use to copy the database becomes the database owner (DBO) on the new database when it is created. After the copy is complete, the destination database becomes a fully functional, independent database. The logins, users, and permissions of the destination can be managed independently of the source database.
Cross-Server Copying
You can also copy a database between two different SQL Database servers that are in the same sub-region or data center. Because the new database is created on a different SQL Database server, it is associated with a different master database. All users in the new database maintain the permissions that they had in the source database. The security principal you use to copy the database becomes DBO on the new database when it is created and is assigned a new security identifier (SID).
For more info, see this link: http://msdn.microsoft.com/en-us/library/ff951624.aspx

Duplicate Schema in Sql Server 2008

I am wanting to duplicate an existing schema with the table structure, but not any of the existing data. Essentially, we are separating two companies that currently share a single schema in the database, and they have the exact same data structure, but we want them in different schemas (for access control purposes).
It is possible to copy the entire table structure of one schema into a new schema without bringing over any of the data?
You can do that in SSMS (Sql Server Management Studio)
Right-click on the database
Script Database as
Create to
File
Do a global search-and-replace in the resulting file, changing your schema name to their desired schema name.
I suggest going forward that you maintain change scripts to apply any needed changes to the DB as the application is further developed. That way, you can just share the change scripts and each apply them when you are ready to upgrade the app version.

How can I ensure a read only user is created for every new database in SQL server 2005?

We create multiple databases in sql server 2005. I would like to make sure that every new database that is created has a specific read only account when it gets created. I know there is a way to write code to do this, but is there a way we can set up a database template of some sort so every time a new database is created the account is automatically added from SQL server side rather than the code side?
If you mean one read-only user account for all databases on a server, you can use this hack:
Create a new SQL Server login
Create a new Database user in model database with db_datareader privilegues.
All new databases use the model db as template, so the user will be available in all databases.
But keep the security issues in mind. ;-)