LocalDB: create db from existing SQL Server database - sql-server

Just wondering if there's a quick way of creating a new localdb from an existing SQL Server database. The idea is to reproduce the "real" db structure in order to run some integration tests from the VSTS during a CI build.
Currently, I'm using the Generate Scripts option to get the SQL for creating the required db objects, but unfortunately it needs some cleaning before it can be run against a new localdb.
Is there an alternative approach for this kind of work?
Thanks,
Luis

Related

How to create a SQL Server database on production server

I'm working on an Angular / .Net core project, and I want to deploy it on my homemade server equipped with Windows Server 2016.
I'm stuck at figuring out the best way to create my database from my migrations files. I've seen some topics on stackoverflow about it, but I don't want to make mistakes on my server, so I'm asking for the best way to do that.
The first option I think is to install Visual Studio IDE on my server. Then I can open my project and run an Update-database command, which will read all migrations files and create database.
But I don't think I'm supposed to install Visual Studio on a server...
The second option is something I saw on StackOverflow. In my development environment, I can use the command dotnet ef migrations script, which will generate a script.
But I'm not sure where I should put this script. I think probably in Microsoft SQL Server Management studio, New query and put my script.
Could you please tell me the best way ?
you need dotnet sdk in order to use dotnet ef migrations script but you can use your development pc to connect to your remote SQL Server and do migrations. for this, just point your connection string to remote SQL Server and use either Update-Database or dotnet ef update database
Another solution exists and You can use SQL server Generate Script to query all your database objects and execute it on target SQL server.
The best way you can do "first create" of your database in production environment is to Generate Script from SSMS (SQL Server Management Studio) and run that script on production Db server. The reason of that is because your database is empty (you can put all of data in script) and you can easily change the name, etc.
After that, on new versions of your application, the best way is to use Update-Database -Script and save/add that script to your deployment scripts.
When you are preparing for go-live, try that scripts with ROLLBACK TRANSACTION, if something fails...

Can SQL Server synchronise a live database and a create script to make an update script?

We are currently updating our SQL Server database create and update scripts by hand, and I'm looking for a better way.
I've worked extensively with MySQL Workbench before, and it has functionality to update a database creation script to match a live database, and in the process also produce an update script.
Is there similar functionality available in SQL Server? If so, can you please provide references to it?
If you're using Visual Studio, the answer is SQL Server Data Tools (SSDT). It comes with SQL Schema Compare functionality. Check it out here: http://msdn.microsoft.com/en-us/data/tools.aspx
SSDT can also do a lot of other stuff, like automated database testing, automated build and deployment of databases, etc.
There are also 3rd party alternatives, such as Red Gate's SQL Compare: http://www.red-gate.com/products/sql-development/sql-compare/

Deploy SQL Server and my dataBase with oneClick setup

I'm asking if it's possible to deploy SQL Server and my database with oneClick setup.
I'm mean that I have to give to my client the setup file that contains my application and my database. The user should just have to click on the setup, and automatically install my application, SQL Server and deploy the database in one operation.
Is that possible?
Thanks but I
need alos to know how to deply te SQL SERVER 2008 runTime?
I mean after installing the application, I have to instal the SQL Server and then deploy the database
You can script all the objects in a database via the SSMS by right clicking on the db -> Tasks -> Generate Scripts -> Check Script All Objects in this database. Save the script to a .sql file and execute it against their SQL Server Instance.
Of course it is possible, your client just needs to provide SQL Server credentials during setup and your code can execute scripts during setup to create all the necessary database objects. If this doesn't fit your definition of "oneClick" than you would need to have this information ahead of time and include it in your installation but that would not be secure and it doesn't make much sense because you'd than have to create a unique setup for each client...

Is there a way to migrate SQL Server to Vistadb (Umbraco)

I am on a shared host and whilst in development (umbraco) I think it would be easier to use VistaDB then package up to install to SQL Server. However, I have already started using SQL Server. Is there a way to migrate my SQL Server (2008) database to VistaDB. I assume the schema is identical but I need a way/tool to move the data to VistaDB.
You could migrate to VistaDB in the same way that you want to migrate data from development to production. Create a package from your current SQL Server-based development site, then create a new empty install of Umbraco with a VistaDB database and import the package there.
This would also be a useful dry run to check that migration to production is going to work as smoothly as you expect.
You can also use the Data Migration Tool in VistaDB to migrate any SQL Server database to VistaDB 4. If you need an older migration (I think the current Umbraco is still using VDB3 files) contact support through the VistaDB.Net site and someone will help you.

Easiest way to copy an entire SQL server Database from a server to local SQL Express

I need to copy an entire database from a SQL Server 2005 on my server over to my local SQL Express in order to run my application for a presentation. What is the fastest/easiest way to get this done?
EDIT: I have very limited access to my server so I don't think I can access the backup file that I could create so that is out.
If the database is not too big, you could use the Database Publishing Wizard.
This is a free tool from Microsoft which creates a complete SQL script of a database for you (not only the tables and stuff, but all data as well).
You can install the tool on your machine, connect to a remote server and let the tool create the script directly on your machine.
You can download the Database Publishing Wizard here.
Apparently the link above doesn't work anymore in 2019.
That's probably because in newer versions of SQL Server Management Studio, the functionality of the Database Publishing Wizard is included out-of-the-box, so there's no need to install it separately.
It's now called the Generate and Publish Scripts Wizard, but it does exactly the same.
You can right click the database -> Tasks -> Generate scripts. Here you can select one, multiple, or all objects. Then in the 'Set Scripting Options' step of the wizard, click Advanced. In here set the property 'Types of Data to script; to Schema and Data.
Having done these steps, make sure you publish to a file. Because only file can handle large amounts of data.
Now you should have all your objects, tables, and data scripted. Now start running the scripts and viola!
Back up the database on the server and then restore it locally in SQL Express.
EDIT: If this is part of your work, surely you can get someone in networks to get you a backup..?
If you can login to both servers (the Express and the 05 Server) using SQL Server Management Studio then you can do a DB Restore from one database to the other. No need for backup files at all.
You can use SSIS's database copy wizard, but it's not quick at all. Is there a DBA there that you can ask for the backup file? That will probably turn out to be the fastest way.
Depending which versions of SQL Server you are using, you might get some mileage out of the SQL Server Database Publishing Wizard from Microsoft. I've had mixed results with this tool in complex environments, but for most simple database scenarios it is a great tool.
An example of a scenario where I ran into difficulties was a DB with multiple distinct schemas, each with their own owner and extreme separation between the tables (don't ask...). As I said, though, most other scenarios have been fine.
Save your database as a sql script
EMS SQL Manager (for example) allows you to backup your database as a script in a .sql file. It is then possible to run this file against any other SQL server. Just update the first line of the script (CREATE DATABASE ....).
You can even fully parameter the script in order to include data from complete or filtered tables.

Resources