Unable to upgrade compatibility level of existing database - sql-server

I have an existing database and I need to update its compatibility level from 120 to 130 or higher even after installing sql server 2019 (developer edition) and Sql Server Management Studio 2018 I am unable to upgrade compatibility level of my existing database.
Here is the screen shot of installed folder (C > Program Files > Microsoft Sql Server)
Installed directory showing list of all compatibility levels
But now showing in database_name > right click > properties > options > compatibility level (option to update compatibility level) or with the query "ALTER DATABASE database_name
SET COMPATIBILITY_LEVEL"
How can I update compatibility level with Sql Server 2016 (Installed)

Related

Bak File Backup Restore Docker Azure SQL Edge in M1 Apple

I try to restore a .bak file Azure Sql Edge container with Azure Data Studio. I have Apple M1 chipset. I am using docker for mssql:
mcr.microsoft.com/azure-sql-edge latest 5dba915af82f 8 weeks ago 1.83GB
I need to install Mssql and restore a database with .bak file. But I get below error:
Restore FilelistOnly from disk = N'/var/opt/mssql/backup/test.bak'
Restore Database test From disk = N'/var/opt/mssql/backup/test.bak' WITH REPLACE, RECOVERY, MOVE 'test_data' TO '/var/opt/mssql/data/test.mdf', MOVE 'test_Log' TO '/var/opt/mssql/data/test.ldf'
Msg 12824, Level 16, State 1, Line 2 The sp_configure value
'contained database authentication' must be set to 1 in order to
restore a contained database. You may need to use RECONFIGURE to set
the value_in_use.
I try to
sp_configure 'contained database authentication', 1;
GO
RECONFIGURE;
GO
I am getting:
Msg 15392, Level 16, State 1, Procedure sp_configure, Line 166 The
specified option 'contained database authentication' is not supported
by this edition of SQL Server and cannot be changed using
sp_configure.
How to restore my backup on azure sql edge?
You're running Azure SQL Edge, which is a special edition intended for IoT scenarios.
Per the docs
Additionally, a database created on Microsoft SQL Server or Azure SQL
can be restored on Azure SQL Edge, provided the database does not
contain any of the features not supported by Azure SQL Edge.
Backup and Restore - Azure SQL Edge
And Contained Databases are not supported in Azure SQL Edge.
So either start with a backup of a non-contained database, or use one of the "regular" SQL Server Editions on Docker.
Regular SQL docker editions for M1 Apple Silicon is still not supported. Azure SQL Edge not usefull for this activity. So can not import bak or bacpac files to local sql via M1 macs!

Backup and Restore SQL Server database from higher version to lower version

I'm looking for a way to create a command line script to backup SQL Server 2016 which can be restored in a older version SQL Server 2012.
We have a daily backup from our SQL Server 2016 using the
BACKUP DATABASE XXXX TO DISK = "C:\BACKUP.BAK"
and this back up is provided to a 3rd party which is running an older SQL Server 2012.
When they use SMSS they get an error stating an error about the incompatible version.
I've tried using ALTER DATBASE XXXX SET COMPATIBILITY_LEVEL = 110 ( targeting even a lower than SQL Server 2012 version)... thinking it can be loaded in their 2012 but when they try to load it, it still states that the backup file is in 2016 (v13.xxx) ?!
Sample backup script
USE MYDB;
ALTER DATABASE MYDB SET SINGLE_USER
GO
-- TARGETING SQL Server SQL Server 2012
ALTER DATABASE MYDB SET COMPATIBILITY_LEVEL = 110
GO
BACKUP DATABASE MYDB
TO DISK = 'C:\TEMP\MYDB.BAK'
ALTER DATABASE MYDB SET MULTI_USER
GO
Can anyone let me know what Im doing wrong?
Thanks
You just simply CANNOT do this - you cannot attach/detach or backup/restore a database from a newer version of SQL Server down to an older version - the internal file structures are just too different to support backwards compatibility. And the "database compatibility level" also doesn't help.
You can either get around this problem by
using the same version of SQL Server on all your machines - then you can easily backup/restore databases between instances
otherwise you can create the database scripts for both structure (tables, view, stored procedures etc.) and for contents (the actual data contained in the tables) either in SQL Server Management Studio (Tasks > Generate Scripts) or using a third-party tool
or you can use a third-party tool like Red-Gate's SQL Compare and SQL Data Compare to do "diffing" between your source and target, generate update scripts from those differences, and then execute those scripts on the target platform; this works across different SQL Server versions.

In SSMS cannot set compatibility level to 2016

I have SQL Server Management Studio v17.4 and I am trying to set the compatability level of a database to SQL Server 2016 (130). In the database properties window It only lists 2008 (100), 2012 (110), and 2014 (120) levels. If I try to use the command
ALTER DATABASE mydatabase
SET COMPATIBILITY_LEVEL= 130
I get the error
Valid values of the database compatibility level are 100, 110, or 120.
This is a major problem because I am trying to run a local copy of my company's database, and more and more changes are getting checked into source control that use TSQL 2016 keywords like AS TIMEZONE.
How can I set this to 2016?

Error in tunning trace from SQL Server Express on machine with SQL Server developer edition

I am facing some performance problem of production SQL Server Express.
I would like to profile SQL Server using SQL Server profiler.
What I have done so far:
On production machine:
I turned on tracing according this answer:
CMD prompt as admin
net stop MSSQL$SQLEXPRESS
net start MSSQL$SQLEXPRESS /T4032
Now, using the SQL Server Management Studio run the following:
dbcc traceon(3605, -1)
After half day of profiling I downloaded trace file from production server from
C:\Program Files\Microsoft SQL Server\MSSQL11.SQLEXPRESS\MSSQL\Log\log.trc
I backuped database and downloaded the backup to developer machine.
On developer machine:
I restored the backup
I opened SQL Server 2014 Profiler
From menu Tools -> Database Tunning advisor
Connect to server localhost (restored backup)
Choose workload log.trc (recorded trace from production machine)
Choose database for workload analysis (restored backup)
Select database and tables to tune (restored backup)
menu Action Start Analysis (F5)
I got the following error:
The specified workload (file or table) has no tunable events. Events must be one of following types - SQL:BatchStarting, SQL:BatchCompleted, RPC:Starting, RPC:Completed, SP:StMtStarting, SP:StMtCompleted for workload trace file or table.
Configuration
Production SQL Server Configuration:
SQL Server Express with Advance Services 2012, x64, RTM 11.0.2218
Developer SQL Server configuration:
SQL Server Developer Edition 2012 2014, SP1, x64, 11.0.3156
What Am I doing wrong?

Compatibility level for SQL Server database

My database hoster allows to restore SQL Server databases with a compatibility level of 90 (SQL Server 2005). My database is created locally with a compatibility level of 100 (SQL Server 2008).
So, I generated script of my database (version 2008) and run in SQL Server 2005, backup and restore to my database hoster, it works. Currently I do likes it.
And then I found ALTER DATABASE that can change compatibility level of database likes
ALTER DATABASE database_name
SET COMPATIBILITY_LEVEL = { 90 | 100 | 110 }
90 = SQL Server 2005
100 = SQL Server 2008 and SQL Server 2008 R2
110 = SQL Server 2012
I turn my database compatibility level using this script in SQL Server 2008, backup my database and restore to my database hoster. But it doesn't work. I want to know why? Is there a better way to fix it ?
You can NEVER restore a database from a newer version of SQL Server (like your 2008 version) onto an older SQL Server (2005) instance.
No matter what you try, no trick, no hack, no workaround - it just cannot be done.
The compatibility level doesn't make any difference either. It just makes your newer database (like on 2008) behave as if it were an older one (like 2005) - so the features you can use are limited to what the older database supported.
But internally - it's still a 2008 database and it cannot be restored to a 2005 instance.
You can't go back to version compatibility of sql server better to go through scripts.
Make a new database
Import the tables in the new database
Then generate the script of procedures and functions and run this script on the new database

Resources