Skip to main content

Database Compatibility ...

Database Compatibility

This article would explain a practical way of using the system stored procedure "sp_dbcmptlevel".

Sp_dbcmptlevel :: Set the database compatibility level.

--------------------------------------------------------------------------------
By default,
for SQL Server 6.5 the comatibility level is 65,
for SQL Server 7.0 the comatibility level is 70,
for SQL Server 2000 the comatibility level is 80
--------------------------------------------------------------------------------


One can check their database compatibility level by executing the sp_dbcmptlevel system stored procedure.

Let me explain the way I made use of this system stored procedure in my previous company. We were having SQL Server 2k in our development environment but for a project our requirement were to use only SQL Server 6.5 (hmm quite old isn't it? when did you last heard about SQL Server 6.5 :) ). Its for sure that we can't purchase 6.5 version for this project alone. At that time sp_dbcmptlevel came to our rescue. We just executed the below query so that our database (get it right, its database level and NOT server level change) compatibility would be set to SQL Server 6.5

-- Replace Pubs with your actual database name
EXEC sp_dbcmptlevel 'pubs', 65

This way if by mistake you use any keywords which are not in version 6.5 it would throw an error. Once the project is done or anytime during the course of the project you can reset the compatibility level back to 80.

For testing purpose

1. EXEC sp_dbcmptlevel 'pubs'
This would give you the current compatibilty information for pubs database

2. EXEC sp_dbcmptlevel 'pubs', 65
This would set the compatibility to SQL Server 6.5 for Pubs database alone.

3. Select top 5* from authors
After executing point 2 if we run the above query it would throw an error because TOP keyword is not available in SQL Server 6.5

4. EXEC sp_dbcmptlevel 'pubs', 80
This would reset the compatibility of pubs database to SQL Server 2000. Now execute the
query mentioned in point 3 to see the top 5 records displayed.

For further reading:

I suggest you have a look at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tsqlref/ts_sp_da-di_5c8c.asp for more details on this topic.

Comments

Popular posts from this blog

Registry manipulation from SQL

Registry Manupulation from SQL Server is pretty easy. There are 4 extended stored procedure in SQL Server 2000 for the purpose of manupulating the server registry. They are: 1) xp_regwrite 2) xp_regread 3) xp_regdeletekey 4) xp_regdeletevalue Let us see each one of them in detail! About xp_regwrite This extended stored procedure helps us to create data item in the (server’s) registry and we could also create a new key. Usage: We must specify the root key with the @rootkey parameter and an individual key with the @key parameter. Please note that if the key doesn’t exist (without any warnnig) it would be created in the registry. The @value_name parameter designates the data item and the @type the type of the data item. Valid data item types include REG_SZ and REG_DWORD . The last parameter is the @value parameter, which assigns a value to the data item. Let us now see an example which would add a new key called " TestKey ", and a new data item under it called TestKeyValue :

Screen scraping using XmlHttp and Vbscript ...

I wrote a small program for screen scraping any sites using XmlHttp object and VBScript. I know I haven't done any rocket science :) still I thought of sharing the code with you all. XmlHttp -- E x tensible M arkup L anguage H ypertext T ransfer P rotocol An advantage is that - the XmlHttp object queries the server and retrieve the latest information without reloading the page. Source code: < html > < head > < script language ="vbscript"> Dim objXmlHttp Set objXmlHttp = CreateObject("Msxml2.XMLHttp") Function ScreenScrapping() URL == "UR site URL comes here" objXmlHttp.Open "POST", url, False objXmlHttp.onreadystatechange = getref("HandleStateChange") objXmlHttp.Send End Function Function HandleStateChange() If (ObjXmlHttp.readyState = 4) Then msgbox "Screenscrapping completed .." divShowContent.innerHtml = objXmlHttp.responseText End If End Function </ script > < head > < body > &l

Script table as - ALTER TO is greyed out - SQL SERVER

One of my office colleague recently asked me why we are not able to generate ALTER Table script from SSMS. If we right click on the table and choose "Script Table As"  ALTER To option would be disabled or Greyed out. Is it a bug? No it isn't a bug. ALTER To is there to be used for generating modified script of Stored Procedure, Functions, Views, Triggers etc., and NOT for Tables. For generating ALTER Table script there is an work around. Right click on the table, choose "Modify" and enter into the design mode. Make what ever changes you want to make and WITHOUT saving it right click anywhere on the top half of the window (above Column properties) and choose "Generate Change Script". Please be advised that SQL Server would drop actually create a new table with modifications, move the data from the old table into it and then drop the old table. Sounds simple but assume you have a very large table for which you want to do this! Then it woul