Migrate a SQL Server database to a lower version - sql-server

I am trying to downgrade a SQL Server 2014 database to a lower version (SQL Server 2012) by using the task Generating scripts found when right clicked on the database.
After I make the settings in order to generate the script, the server does that but when I'm trying to open the file (the script made) on a lower version instance of SQL Server, I get the following error.
System out of memory exception thrown
Could anyone provide some help? Thanks!

As suggested by #usr you can run the script from the command line using sqlcmd:
sqlcmd -S myServer\instanceName -i C:\myScript.sql
Alternatively you can download a trial edition of ApexSQL or Redgate SQL Compare (assuming you have not tried them already) and script over the changes using these tools.

The script is too big for SSMS (a shame!). Run it using SQL Server command line tools.
I find it easier to do this by using Redgate SQL Packager or the two compare tools. They can execute enormous scripts.

Related

sqlcmd for SQL Servers

Faced the problem of using sqlcmd in sqlserver, but I do not know for which server versions it fits, I could not find it. this console does not depend on the version of sql server?
So, if I want to install sqlcmd on sqlserver 2003, it will work or need a version of the server> 2008 ???
Good day,
sqlcmd is not part of SQL Server but external utilities.If you want to use it then you need to install it (together with other tools like SSMS or separately). You can download the last version (at this time) from Microsoft directly from this link.
You should use the latest version even if you use older version of SQL Server (from 2008 and above) since the new version include support for new features. Do not use old version of sqlcmd to connect newer version of SQL Server even so it should work for basic tasks
--- update: adding some more information ---
Here you can find more information regarding how to use the tool:
https://learn.microsoft.com/en-us/sql/tools/sqlcmd-utility

Create jobs in SQL Server Express edition

I am using SQL Server 2008 (Express Edition).
I want to create a job which will delete all data from the all the table(>50) in the DB everyday at night 1:00.
Instead of Deleteting i decide to restore the DB from the Script.
It would have been easy by using SQL Server Agent, But this is limitation in SQL Server Express.
I figured out that we can create jobs "manually" by creating batch files and SQL script files, and running them via Windows Task Scheduler.
I have no clue what i have to write in bat file and sql file.This is my first time where i am working so deeply in SQL configuration. Can someone help please?
Name of the script which i need to restore is test.sql.
If any one has different approach , please share.
Thanks
Prat
Your batch files needs to look like this. Change the path to your .sql file and also put in the sql server info. You can read more about sqlcmd HERE. Also note the case on the switches -S and -i as it does matter.
sqlcmd -S <ComputerName>\<InstanceName> -i C:\test.sql

Connect to localdb with sql-cli

There is the sql-cli utlity (installed with npm) which I am using to connect to various SQL Server machines. It works perfectly, however when connecting to localdb it responds with an error. So the next command line works:
mssql -s SomeServerAddress
But this one doesnt work:
mssql -s (localdb)\v11.0
And it responds with
\v11.0 was unexpected at this time.
Is there any special formatting for the server name to work?
Thanks.
its because (localdb)\v11.0 is not an actual instance as it can only be used inside visual studio.
"The localdb is at the heart of SSDT; it’s similar to SQL Server Express under the hood and runs a full version of sqlserver.exe. However this is throttled by the numbers of CPUs and limits on resources. There are quite a lot of limitations; you cannot upgrade the instance and there is no management and the sqlserver.exe does not run as a service. It is not similar to SQL Server Compact as this is feature-less (no stored procedures or functions) it is actually a DLL file that runs in a process from within Visual Studio, but is not available to task manager or windows. It is awakened when the SQL Server Native Client requests a connection from within Visual Studio. It doesn't stay online forever, it shuts down after time. You can configure where it creates the SQL files required to run. The localdb does not support table partitioning or data compression at the moment. However there are not many features that it does not support. You can however configure SSDT to use a full version of SQL Server i.e. the Developer edition, if your project requires unsupported features; by changing the Debug Connections tring in the projects properies." - Andrew J Fenna
This works:
mssql-cli -E -S (localdb)\mssqllocaldb
The -E is for integrated auth, the -S is the server.
If it does not connect, try to start localdb:
sqllocaldb start mssqllocaldb
This is all that is needed. No need to start Visual Studio or any other tool.
You may alreaady have gone on to bigger and better things, but
mssql -s "(localdb)\MSSQLLocalDB"
has worked for me.
Regards

Is there some way I can update the statistics on my SQL Server 2012 database?

I don't have the management studio installed and cannot install the express version as there seems to be a problem with my computer set up.
However I have VS2013 and I can open up query windows.
I created Indexes but then since then I have added a lot of new data. Is there some way I can update statistics for my SQL Server 2012 database from the SQL Script command line?
Try EXEC SP_updatestats to update all database statistics.
You can access the SQL command line using the tool sqlcmd that is installed as part of SQL 2012.
Here's a link to the update statistics command that you'll need to put together and execute.
http://technet.microsoft.com/en-us/library/ms187348.aspx
You can always create a script for the update statistics command, then execute that.
If you have both SQL and SQL Express installed, please make sure that you are connecting to the correct instance of SQL Server. the machine name alone or localhost should take you to the full sql 2012, (the default instance name for this is MSSQLSERVER) and the SQL Express should have an instance name of SQLEXPRESS (if I remember correctly) you'll need to use the naming convention server\instance to make the connection (you probably knew this bit already)
Try this
EXEC sp_updatestats;
MSDN

How to import .sql file into SQL Server Express

I have a plain sql file with some SQL INSERT statements.
Is it possible to import it in my local SQL Server Express instance?
You can use Management Studio Express edition. You can download the latest version here - which will work against SQL Express 2005, 2008 and 2008 R2.
If you don't want to install SSMSE then you can use sqlcmd at a command prompt, e.g. something like this (assuming Windows auth and an instance called "SQLEXPRESS"):
sqlcmd -S .\SQLEXPRESS -E -i "C:\path\file.sql"
The easiest way would be simply open the file in the Sql Management Studio and run it. Since the target table is already created, of course.
You can open it via Query analyser and run
Here is the tool Sql_Server_Script_Executor
You can add single/multiple file/folder and your files will comes up in the list. Click the execute button and done
It contains three transaction modes.
1. Execute scripts within one transaction
2. Execute scripts on separate transaction
3. No transaction
All you have to do is open Microsoft SQL Server 2008 Management Studio.
Then use File -> Open.
Open the file from the proper location and you'll get all the SQL statements there. After that you can execute them.
Hope this helps.

Resources