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

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

Related

Copying a small database in SQL server

I have a small SQL server 2014 database that simply has just 3 tables and some information in them for a school group project and am wondering what the easiest way would be to have a group member be able to access the database rather then manually copying down all the information from each row and column. We wouldnt be changing any information in the database. Thanks.
I would create a database role. After you create the role add each person that needs access to that role then grant that role read access to each table. This way if a person in that group no longer needs access you can just remove them from the role and vise versa.
Since this is a school project I am assuming that the SQL Server database is a local DB and not on a shared server. You could perform a backup and restore where you back up the database on your machine and send them the back up files and they can use them to perform a restore to create the database on wherever.

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.

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. ;-)