Avatar of Jess31
Jess31
 asked on

SQL Server / Update DB?

I have a db on a 2012 server. I have the same db on a 2016 server. I made changes to the one on the 2016 server. Now I want to update the 2012 with my 2016.
I have rights to this specific db on the 2012 but I'm not sure if I remove this db that I would right to create it again. On the 2016 I have full rights for everything.
How do I do this?
Microsoft SQL Server

Avatar of undefined
Last Comment
Vitor Montalvão

8/22/2022 - Mon
Vitor Montalvão

What do you want to update?
Whole database? Some stored procedure or function? Some tables? Data only?
Jess31

ASKER
any stored procedures or function that have been added or changed, same with tables
Vitor Montalvão

If you want to perform this only once, then best thing to do is to script the changed objects and run the script in the SQL Server 2012 instance.
If you want to perform this in a regular way, set a Replication between SQL Server 2016 database and the respective DB in SQL Server 2012. When you have a new object just add it to the articles so it can be replicated.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Jess31

ASKER
I tried using the script database. But when I run it on the 2012 I get these errors "There is already an object named..." Is there away to have the script override any existing object?
Dung Dinh

If you script changed objects from SQL Server Management Studio, you should script with DROP and CREATE option. But if an object is existing on 2012 and some users are granted permissions on the object, you will need to grant again after updating.

If 2012 database is still used for LIVE environment, you should have a backup strategy for the objects before modifying them.
Jess31

ASKER
Is it possible to create bacpac on 2016 and import it in 2012?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Anthony Perkins

Or you could simply purchase SQL Compare from Red-Gate and let that app take care of all the dependencies.
Vitor Montalvão

I tried using the script database. But when I run it on the 2012 I get these errors "There is already an object named..." Is there away to have the script override any existing object?
You can configure the script to bypass or drop existing objects. What do you prefer?
Jess31

ASKER
I recreated the db on the target server. I created the scripts and ran it on the target. The Tables and stored procedures/functions seems to have been creted.

But I got errors on these lines in the script and the diagram didn't get created

ALTER DATABASE [ShipBill] SET TRUSTWORTHY OFF
ALTER DATABASE [ShipBill] SET HONOR_BROKER_PRIORITY OFF
ALTER DATABASE [ShipBill] SET DB_CHAINING OFF
ALTER DATABASE SCOPED CONFIGURATION SET MAXDOP = 0;
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET MAXDOP = PRIMARY;
ALTER DATABASE SCOPED CONFIGURATION SET LEGACY_CARDINALITY_ESTIMATION = OFF;
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET LEGACY_CARDINALITY_ESTIMATION = PRIMARY;
ALTER DATABASE SCOPED CONFIGURATION SET PARAMETER_SNIFFING = ON;
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET PARAMETER_SNIFFING = PRIMARY;
ALTER DATABASE SCOPED CONFIGURATION SET QUERY_OPTIMIZER_HOTFIXES = OFF;
ALTER DATABASE SCOPED CONFIGURATION FOR SECONDARY SET QUERY_OPTIMIZER_HOTFIXES = PRIMARY;
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
Vitor Montalvão

Seems to me those commands aren't compatible with lower versions of SQL Server. You can just remove them from the script.
Or if you wish, when generating the script, click the Advanced button and then choose the target SQL Server version so the script will run without error.
Generate-Scripts.PNG
Jess31

ASKER
the script I created I had set to version 2012. I also set my db to compatibly 120 which is for 2012
Vitor Montalvão

That's strange because for example, this command only exists in SQL Server 2016 as you can state by the MSDN article.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jess31

ASKER
I just tried generate scripts again, using 2012 target, but this time only fore Schema and it put this scopped configuration in as well.
Vitor Montalvão

Might be some kind of bug then. Can't you just remove those lines from the script?
Jess31

ASKER
I had done that and all seemed fine. But I'm wondering why the Diagrams didn't get created. Is it not suppose to be?
Your help has saved me hundreds of hours of internet surfing.
fblack61
Vitor Montalvão

You are only script the objects and not importing the data, right?
Check if table sysdiagrams has records or it is empty.
Jess31

ASKER
I generated scripts for both Schema and Data. Both seemed to import fine despite the errors mentioned about.
sysdiagrams in my source contains 5 rows, in the target 0
Vitor Montalvão

Only sysdiagrams didn't import the data? The rest of table has imported data? That's weird.
You can always import the data manually using the Import/Export wizard:
ExportData.PNG
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Jess31

ASKER
Yes, only sysdiagrams didn't import.
The Export data you show - can I use it to just export diagrams?
Vitor Montalvão

Yes, you can. Just choose the table instead of all objects.
Jess31

ASKER
Export Data wants me to specify another db or such like to export it to. But the db to which I am looking to copy it is on another non connected computer.
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck
ASKER CERTIFIED SOLUTION
Vitor Montalvão

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.