Microsoft SQL Server 2005 Merge replication deleting records on subscriber - sql-server-2005

I created a simple merge replication. I used the default settings to create the publication which was creating a script to create the snapshot that Occurs every 14 day(s) at 12:05:00 AM. First, I am not sure why it needs to run every 14 days. Second, after researching for hours, I could not figure out how to not replicate deletes. Whenever I create the subscription and run the script, it creates a mirror image of everything that the publisher has and deletes any records in the subscriber that were not in the publisher. I need both publisher and subscriber to be merged without any deletes...Just inserts and updates.
I am a beginner when it comes to Microsoft SQL Server Management Studio 2005. If I need to modify any scripts or stored procedures could you please let me know how to do that. Whenever I try to modify a script, it asks me to save it to a file and I am not sure how to get it updated with the changes in the database.
Thanks
-Dimitry

Related

SQL Server database : amalgamate 90 database update scripts into a single script

I have an application that has been released for several years. I have updated the SQL Server database around 90 times and each time I have created an update SQL script, so when the user runs the new software version the database is updated.
I would like to amalgamate all the updates into a single SQL script to make deployment faster and simpler, is there an easy way to do this? I presume I could simply grab the latest database after it has run through all 90 updates via SQL Server Management Studio?
EDIT
For clarification; the software I wrote automatically applies new database updates when the user downloads the latest version. This is done via C# / .Net and look for an embedded sql script on startup in the format XX_update.sql calling each script one by one i.e.
1_update.sql - this creates the tables and initial data etc. This was my initial release database.
2_update.sql - updates to the initial database such as adding a new SP or changing column datatype etc
3_update.sql
4_update.sql
...
90_update.sql (4 years and lots of program updates later!).
Ideally, I would install my software and create a brand new database running through all 90 update scripts. Then take this database and convert it into a script which I can replace all 90 scripts above.
This is too long for a comment.
There is no "easy" way to do this. It depends on what the individual updates are doing.
There is a process you can follow in the future, though. Whenever an update occurs, you should maintain scripts both for incremental updates and for complete updates. You might also want to periodically introduce major versions, and be able to upgrade to and from those.
In the meantime, you'll need to build the complete update by walking through the individual ones.
I use a similar system at work and while I prefer to run the scripts separately I have amalgamated several scripts sometimes when they have to be deployed by another person with no problem.
In SQL Server the rule is that as long as you separate the scripts by go and use SQL Server Management Studio or another tool that process the batch separator properly there is no problem in amalgamating it, because it would look like separate scripts to SQL Server (instead of being sent to SQL Server as a one big script the tool send it in batches using the go as the batch separator).
The only problem is that if you have an error in the middle of the script, the tool would continue sending the rest of batches to the server (at least by default, maybe there is an option for changing this). That is why I prefer when possible using a tool to run then separately, just to err on the safer side and stop if there is a problem and locate easily the problematic command.
Also, for new deployments your best option is what you say of using a database that is already updated instead of using the original one and apply all the updates. And to prevent being in this situation again you can keep a empty template database that is not used for any testing and update it when you update the rest of databases.
Are you running your updates manaually on the server. Instead, you can create a .bat file, powershell script or a exe. Update scripts in your folder can be numbered. The script can just pick up updates one by one and execute it over the database connection instead of you doing it.
If you have multiple script files and you want them to combine into one,
rename these as txt, combine, rename the resulting file as sql.
https://www.online-tech-tips.com/free-software-downloads/combine-text-files/
This is easy. Download SQL Server Data Tools and use that to create the deployment script. If there's no existing database, it will create all the objects, and if targeting an older version it will perform a diff against the target database and create scripts that create the missing objects, and alter the existing ones.
You can also generate scripts for the current version using SSMS, or use SSMS to take a backup, and use a restore to in an install.

SQL management studio 2012 table from an other database keep coming back automatically

I am learning T-SQL. Every time I create a new database, table from a deleted database keep on appearing automatically. :-( don't know how to stop it.
Check in the System Database -> Model. Delete the table from there. Then create a new database and it should "appear" again.

Get Data from a Website and update a SQL Server 2008 R2 Table

I'm wondering if it is at all possible to take data from a website and update a table in SQL Server 2008 R2 at a given interval of time?
The website in question updates every 5 minutes, changing the values of two numbers. As stated above I'm using SQL Server 2008 R2 and I also have Visual Studio 2013 if that matters at all. I need to take these two numbers every 5 minutes and update a table I have created on the SQL Server.
I know I can use an Excel macro to do this, which I already have done, but my employer wants to bypass this altogether.
If this is possible, say via a VS application, then any helpful links or suggestions would be greatly appreciated.
Thanks in advance!
You can create an SSIS package with a "script task".
This task could read the website and return the information.
Then store it in your table.
To finish configure a job that call this SSIS package every 5 minutes.

How to use Triggers in SQL Server 2012 to archive and delete

I will be honest, I know nothing about SQL Server other than what I have tried to pack into my brain in the last two days.... I have found a couple of scripts on your website that sounded like they would work What are ways to move data older than 'Y' days to an archive/history table in MySQL?. This one in particular really seems like it would fit my needs.
But I want to insert the data into a table or database on another partition of the same server and can't figure out how to change the location.
I have SQL Server 2012 Express, running on a Windows Server 2008 R2 service pack 1. We started the database on 11/21/2013 and we hit the 10 GB limit on 12/30/13. We design crowns & bridges, implants and dentures so we have multiple CT scans per patient that get manipulated in 3D imaging and CAD programs multiple times so it creates a lot of data very quickly.
Questions:
Should I try to use the triggers built in to my PatientNetDB? [OnAfterDeleteDataSets & OnAfterInsertDatasets]
If so how do I change it to make it work like the question from the user I copied above?
We may need to pull data back out of this archive, how in the heck do I do that?
I really appreciate any help you can give me, remember I am a total newb to this stuff and unfortunately will need extremely simple step by step or copy and paste directions/scripts.
Thank you so much!
Linda Saylor
No, don't use triggers for archiving/deleting. Trigger are fired when specific operations occur - INSERT, UPDATE or DELETE - on certain tables, and you cannot control when and how often triggers are fired. Therefore, triggers should be very small and nimble - you should NOT put large and long-running operations into a trigger. A typical trigger might update a row that's been inserted, or it might put a row into a separate table (an Audit or Command table) - but the trigger itself should never much processing.
What you can and should do is to have scheduled tasks - unfortunately, the SQL Server Agent is not available in the Express edition. With SQL Server Agent you could run certain processing operations (T-SQL scripts) at scheduled intervals, e.g. once every night etc.
Since you're using the Express edition, you'll have to find another way to run a task at given times, possibly by writing a small wrapper in your language of choice (C#, VB.NET, whatever), have that scheduled by the Windows scheduler (Scheduled Tasks in your Windows start menu), which would then kick off / execute a T-SQL script to run the cleanup process and archive your data.

Strange Sql Server 2005 behavior

Background:
I have a site built in ASP.NET with Sql Server 2005 as it's database. The site is the only site on a Windows Server 2003 box sitting in my clients server room. The client is a local school district, so for data security reasons there is no remote desktop access and no remote Sql Server connection, so if I have to service the database I have to be at the terminal. I do have FTP access to update ASP code.
Problem:
I was contacted yesterday about an issue with the system. When I looked in to it, it seems a bug that I had solved nearly a year ago had returned. I have a stored procedure that used to take an int as a parameter but a year ago we changed the structure of the system and updated the stored procedure to take an nvarchar(10). The stored procedure somehow changed back to taking an int instead of an nvarchar.
There is an external hard drive connected to the server that copies data periodically and has the ability to restore the server in case of failure. I would have assumed that somehow an older version of the database had been restored, but data that I know was inserted 7 days and 1 day before the bug occurred is still in the database.
Question:
Is there anyway that the structure of a Sql Server 2005 database can revert to a previous version or be restored to a previous version without touching the actual data? No one else should have access to the server so I'm going a little insane trying to figure out how this even happened.
Any ideas?
Using SQL Server's built-in backup and restore mechanism, there is no means to pick only certain objects to restore. With transaction log backups, you can restore to a point in time which might be before a certain transaction or ALTER statement was made but that's the closest you get. There are tool's which will let you pick certain objects to restore however they work by either restoring the database to a copy and copying over the objects you want or reading the backup directly and copying out those objects. In other words, this is not something could have happened using the built-in tools accidentally. My guess is that someone accidentally ran an old script of the stored proc(s) that reverted it.
It would be trivial to change a stored procedure without touching any data, or any other stored procedure. How who why when, that's the problem.
One suggestion, run
select * from sys.procedures
and check the create_date and modify_date columns, for both your problem procedure and all other procedures in the database.
I've witnessed similar things happening with an app I have installed at one client location. Every so often the s'procs revert to an older version.
It's just one client, the app is installed at several others which have never had this issue, and they happen to be a school district as well. It happens about once every 3 months or so, and no one should be touching that machine. I'm not even sure they have anyone in house that would know how to open enterprise manager.
Out of curiousity, what backup software is your client using? and, after checking the creation / modify dates on the procedures, did a server reboot occur around that time?
The reason I ask is that my client has backup software that does some really weird things on that server. For example, on reboot it has to "play back" changes, including file operations, since the last successful backup. Also, is it installed in a VM?
Through Data Transformation Services (DTS) ? or if the scripts that set up the database are available someplace..