Default read-only user for MsSql database - sql-server

We're currently using a tool (no way to change this as it is tied to a larger machine) which creates databases (not tables) on a SQL server (MSSQL 2014) on a weekly basis. These are named:
RESULT_201801
RESULT_201802
...
Over the course of one week, those databases will get filled with data until the beginning of a week where the next one will be created.
Now I need to extract specific data from all available databases. The issue which arises is, that I need to have a user which is allowed to read data from each of that databases. I could easily create that user and add it manually but doing this each week monday morning doesn't seem the right thing to do.
Is there a way to have such a user (with read-only permissions) for the whole database server? What would be the correct way to do that? Will I need to resort back to using a script, executed hourly, checking permissions?

Related

Database archive strategy

We have oracle database having 10 yrs of data. We want to archive them as application is getting slow due to large sets of data. Issue is that system still needs to access old data if user wants. So how can we design that? For example if we archive the data from 2010 to 2015 in archive database and delete the data from the current database, application will query based on a date to some table which has a data range and then connect to appropriate database i,e current or archive. There is also a possibility to get all the data from both databases in some cases.
How to archive records in multiple tables within one access database
Above solution talks about archiving but i need to have strategy if user wants to access the old records.
Thanks

Copy records from a table on one SQL instance to an identical table on a different SQL instance

We had an intern who was given written instructions for deleting old data from a database based on dates (from within our ERP system). They were fascinated by the results and just kept deleting instead of stopping at the required date. There are now 4 years of missing records in the production database. I have these records in my development database, which is in a different instance on a different server. Is there a way to transfer just those 4 years worth of data from my development database to my production database, checking, of course, to make sure there are no duplicates (unique index on transaction number).
I haven't tried anything yet because I'm not sure where to start. I do have a test database on the same instance as the production database that I could use to test the transfer with.
There are several ways to do this. Assuming that this is on a different machine, you will want to create a Linked Server on your dev machine to link to the target server (Or, technically, a link from the production server to your dev machine could be used as well). Then, perform an insert of the selected records from the source to the target.
More efficiently, you can use the Export Data functionality. Right click on the database (Not the server / instance, but the database) and select Tasks / Export Data from the popup menu. This will pop up the SQL Server Import and Export Wizard. Use your query above to select the data for export.
If security considerations interfere with this, create a duplicate of the table(s) with alternate names (e.g. MyInvRecords) in a new database, and export the data into those tables. Back up that DB, transfer it to someplace accessible from the target server, restore that DB, then transfer the rows back into the original DB.
I haven't had to use anything but these methods before, so one of them should work for you.
A basic insert will work just fine.
Insert ProdDB.schema.YourTable
([Columns])
select ([Columns])
from TestDB.schema.YourTable
where YourDateRange predicates here

How to import tables of a database in SQL Server to another SQL Server on a different computer programmatically?

Good day :-), I'm a beginner when it comes to asking questions here so please bear with me..
First, let me state the example problem at hand:
Company "A" has 4 branches, each placed in different provinces. Each branch, including the main company has an application that inputs a person's profile and saves it to SQL Server database. All data entered by the branching companies must be submitted to the main branch once in a month. But the main director doesn't want those data to be submitted via cloud, he wants it in a flash drive and one individual from each of those branches must travel to the main company, and submit the flash drive with the data inside.
Because if I just use backup & restore method, they will overwrite everything.
Thus, I have created a dummy database to hold those data. Same table, and each table column has the same data type as the original.
Using VB.NET how does one export the table of a database to a dummy database programmatically?
And once exported, how does one import it to the main company's database?
I'll be grateful if you provide me solutions or if you can point me out to the right direction. Also is my method correct?
You can import/export data from one server to another by using Linked Server.
we can do this also by using sql scripts for using simple select & insert query referring the "Servername.Database.tableName"
Now, if you need to do this in a timely manner, for example for every night you need to import/export the data, what i would suggest is to use Sql Agent. Here you can provide timing to execute the script such as date time and whether it is recursive etc...
with the script of import /export to targeted to specific server.
Ps:
Other approch would be to you use SSIS.
Hope this helps.
Thanks,
Satish

How to add data in database from .bak file by sql query

I have backup files. I want to add that data to the existing database not over write it.
Scenario:
The software is installed on different systems. The data is entered from different PC's. but the data is of same type. After taking the backup(.bak)file on run-time. Now i want to combine that all data in a single database not overwrite it. I have tried How to restore to a different database in sql server? I am out of that option and after so much googling i cant get answer.Just found to overwrite the database but i dont want to loose any of the data. Thankz

Can you do a partial restore to an ms crm db?

Is there any way (3rd party product or other method) to do a partial restore to ms crm?
Say a user accidentially deleted an account. Is there anyway to restore just that single account and corresponding notes, activities etc?
We limit users' permissions but inevitably they will have permission to delete some things and will want to get that item from a backup.
Right now the only method I can think of is to restore the .bak file to another db and write a bunch of code using the sdk to re-create the items. Are there any other options?
Red Gate has a tool which will let you restore just certain objects from a database.
Idera has this new virtual database tool where you basically mount the backup as a SQL Server database.
Full disclosure - I haven't used either for this kind of thing - I've always either used audit trails or restored the database and extracted the data manually.
You are correct in that you can only restore to a different database and work from there.
You could then use something like Red Gate data compare to extract the desired rows (14 day trial, but it's worth it's weight in SO Rep anyway)
To be honest, I'd go with
Right now the only method I can think of is to restore the .bak file to another db and write a bunch of code using the sdk to re-create the items.
After all, 'Its the only way to be sure....', not to mention the (extremely) vague chance of another record being created with the same GUID, which would cause assorted 'bad stuff' to happen.
Yes, a small number, but still more than 0...

Resources