How to develop for SQL Server 2008 using 2012? - sql-server-2008

When I use MSBuild 4 I can target .NET Framework 3.5 and older versions, and all features available only on the version 4 will not be available on that project.
I would like to do a similar thing in SQL Server 2012. Can I configure a database in it to behave similary to a SQL Server 2008 one? Can I make one database to not accept commands only available to SQL Server 2012?

You can set the Compatability Level within the database properties.
Right Click the Database
Click Properties
Select Options
Choose the Compatability Level
110 = SQL 2012
100 = SQL 2008 & 2008 R2
90 = SQL 2005
This option only affects the behaviour of this particular database, not the entire server. It should be regarded only as partial backwards compatibility. If your intention is for SQL Server to treat this database as a SQL 2008 database, then the best way to do this would be to run it within SQL 2008 rather than SQL 2012.
Here is a very detailed explanation: http://technet.microsoft.com/en-us/library/bb510680(v=sql.110).aspx
T-SQL
ALTER DATABASE database_name SET COMPATIBILITY_LEVEL = { 90 | 100 | 110 }

Related

How to check sql script compatibility agains SQL 2008

I have installed SQL 2012 and I must create a application compatibility with SQL 2008. Is any way to check that all scripts that I write are compatibility with SQL 2008 without installing SQL 2008?
I believe that there are two thing that you will need to do to ensure that your app is compatible with SQL Server 2008.
First, the easiest way that I have found to find issues caused by deprecation between versions is to use the sql server profiler tool.
http://www.mssqltips.com/sqlservertip/1370/identifying-deprecated-sql-server-code-with-profiler/ is an excellent introduction into that.
Second, you need to change the compatibility level of the database to the level of SQL Server 2008.
ALTER DATABASE database_name
SET COMPATIBILITY_LEVEL = { 90 | 100 | 110 }
So for you that would be ALTER DATABASE database_name SET COMPATIBILITY_LEVEL = 100;
Some things to keep in mind. This will not change the underlying way that sql server executes the query internally, new enhancements to the query optimizer or algebrizer will not be excluded because of the compatibility level. From what I understand this functionality mainly disables language constructs that were not introduced in the version that you are interested in. That being said, it shouldn't make any difference in what you are trying to accomplish.
This is a similar question (with a good answer) regarding 2008 and 2005: Using SQL Server Express 2008 with SQL Server 2005 database -how to check for compatibility
You can find here the complete list of compatibility mode changes: ALTER DATABASE Compatibility Level (Transact-SQL)

Create script in SQL Server 2008 which is compatible with SQL Server 2000

I have a Database in SQL Server 2008 and i want to create the complete database script which is compatible with SQL Server 2000. All the datatypes that I've used are compatible with SQL Server 2000.
Here's what you'd do for SQL Server 2000 compatability:
Right-click on your database, Tasks -> Generate Scripts...
Choose your entire database
In Set Scripting Options click the Advanced button
There is an option for Script for Server Version
Select the drop down option for SQL Server 2000

Migrate from sql server 2000 to 2008 r2 - how to

I have a database working on SQL Server 2000. We are now migrating to a new server with SQL Server 2008 r2. Can anyone please point me to some resource or howto?
I'm not really finding my way around SQL 2000.
Thank you!
Basically, what you need to do is:
backup your database in SQL Server 2000 to a .bak file
move that *.bak file to your new server
restore that database onto your new server
You're done! There's really nothing more to it..... just backup (on your old system) and restore (on your new system).
So where exactly is your problem ??
Update: as #Péter correctly mentions: this leaves your database in the SQL Server 2000 compatibility mode. This means: even though you've "migrated" to SQL Server 2008 R2, you can still only use the 2000 features.
In order to see what compatibility mode your database is in, check the sys.databases catalog view:
SELECT * FROM sys.databases WHERE name = 'YourDatabaseName'
One column is called compatibility_level and contains an INT; 80 = SQL Server 2000, 90 = SQL Server 2005, 100 = SQL Server 2008 / 2008 R2 and 110 = SQL Server 2012
In order to change your database to a different compatibility level, use this command:
ALTER DATABASE YourDatabaseNameHere
SET COMPATIBILITY_LEVEL = 100;
This will put your database into the "native" SQL Server 2008 (and 2008 R2) mode and now your migration is complete, you can use all the new SQL Server 2008 R2 features.
I would start by running the Upgrade Advisor against the 2000 server (during low utilization or off hours) to see what recommendations it makes and fully address each: http://msdn.microsoft.com/en-us/library/ms144256.aspx
Here too is a white paper from MS on the topic: http://download.microsoft.com/download/2/0/B/20B90384-F3FE-4331-AA12-FD58E6AB66C2/SQL%20Server%202000%20to%202008%20Upgrade%20White%20Paper.docx
A lot could go wrong...too much to cover in a forum setting. But then again nothing could go wrong...the best plan, test, and then test some more.
The others answers are correct from a technical perspective but not from a support point of view.
I don't think Microsoft support a direct upgrade from SQL Server 2000 to SQL Server 2008 R2. That doesn't mean it is hard, just that it is not supported. (Which may or may not be significant for your scenario)
You can upgrade your SQL Server 2000 instance to SQL Server 2008 R1 and then perform a subsequent upgrade to SQL Server 2008 R2. (Or even SQL Server 2012 if you are so inclined)
I am currently doing the same thing.
Creating your SQL 2008 database from a 2000 restore bak is a good first step. Most of the work for me was dealing with the user permissions, and making sure that the users were in sync with the database login, and that we didn't have a database schema generated by the backup tied to that user that would cause problems if we tried to recreate that database user.
What we ended up doing was:
1) Create a script. We had a script that would dynamically write a script to do the following: drop login, drop db user, drop schema, recreate login, recreate user, grant user permissions.
2) Restore database.
4) Run the generated script
Edited Apr 2012 because original link changed to latest version, SQL Server 2012
For an "in-situ" upgrade (MSDN links):
... to SQL Server 2008 R2
You can upgrade instances of SQL Server 2000, SQL Server 2005 or SQL Server 2008 to SQL Server 2008 R2.
... to SQL Server 1012
You can upgrade from SQL Server 2005, SQL Server 2008, and SQL Server 2008 R2 to SQL Server 2012.
yet another option is to try to connect database (files) of sql2k to sql2k8 directly.
The simpliest way is to back up your database in SQL 2000 to a .bak file and move it. Do a restore and everything should be fine. Run a sp_Users_Loging to identify the users in the orphan server.

Restoring SQL 2008 R2 db on SQL 2008 Standard

I'm trying to take a SQL Server 2008 R2 Expression db and restore it on my local SQL Server 2008 standard, however it gives me the error:
The media family on device 'C:\jtoth\Backups\ucampus.bak' is incorrectly formed. SQL Server cannot process this media family.
R2 is version 660 and standard is 655 and I know that you can't restore to an older version, but there has to be some way around this. Is there some free tool for scripting out the entire R2 database (including not just structure but inserts for the data) that I can then run on my standard instance?
Normally one of
SSIS (via the import/export wizard)
3rd party tool from Red Gate or similar.
You're right that the backup cannot be restored. See: SQL Server 2008 R2 bumps the database version. Your best bet would probably be the Red-Gate compare tools.
Use the Copy Database Wizard!, the Copy Database Wizard lets you move or copy databases and their objects easily from one server to another.
In SQL Server Management Studio, right click on the database, choose Tasks, then "Generate Scripts". Options in there to generate full scripts including the table structure and all the data. Additionally you can choose which version to script for.
Visual Studio has a Database Compare tool. Might be handy. See the Data menu. Not as good as 3rd party tools though..
Just an idea - how about changing compatibility level to SQL Server 2005 before backup? That is of course if nothing 2008 specific was used.

How to move SQL Server 2008 to the cloud?

I have a large (~40gb) SQL Server 2008 database that I would like to move to the cloud.
The database uses a lot of SQL Server 2008 specific (and non-specific) features (SQLCLR, xml, indexes, partitions, etc). Thus, my preference would be to use the exact database, but in the cloud.
What are my options? The new SQL Azure only allows small databases, and a subset of TSQL. I want to whole thing. I would still like to connect to it using Management Studio.
If you want "the whole thing" and want to be able to connect to your SQL-Azure store with SSMS, you'll have to wait until SQL Server 2008 R2 (a.k.a. SQL Server 2010) is out - sometime in 2010.
The SQL Server 2008 R2 November CTP has just had such an announcement - the SSMS for that version will be supporting SQL Azure.