Link to home
Start Free TrialLog in
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?
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

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

ASKER

any stored procedures or function that have been added or changed, same with tables
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.
Avatar of 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?
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.
Avatar of Jess31

ASKER

Is it possible to create bacpac on 2016 and import it in 2012?
Or you could simply purchase SQL Compare from Red-Gate and let that app take care of all the dependencies.
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?
Avatar of 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;
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.
User generated image
Avatar of Jess31

ASKER

the script I created I had set to version 2012. I also set my db to compatibly 120 which is for 2012
That's strange because for example, this command only exists in SQL Server 2016 as you can state by the MSDN article.
Avatar of 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.
Might be some kind of bug then. Can't you just remove those lines from the script?
Avatar of 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?
You are only script the objects and not importing the data, right?
Check if table sysdiagrams has records or it is empty.
Avatar of 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
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:
User generated image
Avatar of Jess31

ASKER

Yes, only sysdiagrams didn't import.
The Export data you show - can I use it to just export diagrams?
Yes, you can. Just choose the table instead of all objects.
Avatar of 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.
ASKER CERTIFIED SOLUTION
Avatar of Vitor Montalvão
Vitor Montalvão
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial