i'm using mssql for our database.
somehow previous developer before me was set up some table connected to secondary file group instead of the primary file group.
is there any way for us to make it stop string into the secondary file group and insert into primary file group.
because when we have a consultation with a DBA and found out it's not suitable.
Related
In a SQL Server 2017 or Azure SQL Database database, is there a way to identify rows in the history table that were deleted from the current table, without specifically executing a query that finds all primary key values in the history table that do not exist in the current table? I suspect there isn't but wanted to make sure I'm not overlooking anything.
We have a primary Database(Publisher) which is replicated into a secondary database(Subscriber - not updatable) in another SQL server instance. Both are SQL server 2012 instance and replication is Transactional. The secondary database is used only by the reporting team.
Let's say we are having a main table and two more child tables that are being replicated. Now in Secondary database, We are planning to have a queue which should contain the recently replicated records as soon as it enters the secondary database. This is to let the reporting applications know about the new records to be processed. I need the primary key from our main table to go into this queue. Is there any system objects which i can make use of.
For example:
In Primary Database:
Insert into table1(Id,Name) values(5,'abc')
Insert into table1(Id,Name) values(6,'xyz')
Once these two records reach the secondary Database, I want the Ids '5' and '6' to be inserted into that queue. The Queue can be a just another table.
Note: I have an idea to filter out records based on CRUD date but again we need something to trigger this stored procedure as soon as new records enter(rather than a scheduled job). But I feel there must be a smarter way than this.
I have a SQL Server 2008 database. I need to capture Insert/Update/Delete operations on every table in the DB, take the affected primary key and insert into another table ChangeLog. ChangeLog needs capture the PK, source table, operation type.
I don't want to write triggers for every table. Whats the simplest way to do it?
Use case : I connect to SQL Server from Solr. The change log is used for delta import.
I'd start by taking a look at SQL Server Change Tracking and see whether it'll do what you need. It's built in and simple enough to access:
Change Tracking Overview
You don't want to write a trigger for every table because you think it is hard.
Query for a list of each table
Query for each table's primary key
Create a trigger script for add, update and delete to write to the ChangeLog table using the data for each table and primary key.
It's really not that hard to build this script and apply it to your database. If you can write it for one table, you can automatically build scripts for each table. With an error check (does trigger exist), you can run this as new tables are added.
I want to run an alter database command (change the owner) but being part of the HA Group, the database is in read-only mode. I changed the primary so I am guessing I have to force a failover and then update it? Is there a simple way to unjoin or suspend (looks like suspend keeps the read only mode turned on), make the change, and then join it back?
The database owner detail is stored in the master.sys.sysdatabases table, and not on the user database. So when you run the statement on the primary database, it will not transfer to the secondary database.
Changing the database owner requires a read-write database.
try failing over to the secondary database and make it as new primary database, and then change the database owner of new secondary database. then switch back to primary
Reference: Perform a Planned Manual Failover of an Availability Group (SQL Server)
Regards,
Suing
I have a database in which two tables have a 1:1 relationship using foreign keys. Table one is called Manifest and table two is called Inventory. When an inventory record is added using the application this is built for it uses a foreign key to reference the matching record in the manifest table. In addition, this causes an update to a column in the manifest table for the matching record called Received (datatype: BIT) to 1. This is used for reconciliation and reporting purposes.
Now here is where it gets tricky: This database is synchronized to a server database using Sync Framework in a client-server relationship. The Manifest table is synchronized in one direction from server to client, and the Inventory table is synchronized from client to server. Because of this the "received" column in the Manifest table is not always updated accurately on the server-side after a sync.
I was thinking of creating a stored procedure to perform this update, but I'm a bit rusty on my SQL (and T-SQL). The SP I was thinking of using would use a CURSOR to locate any records in the inventory table where the foreign key is NOT NULL (this is allowed due to exceptions where we receive something that was not in the manifest). The cursor would then allow me to iterate though all the records to locate the matching record in the manifest table and update the "received" column. I know that this cannot be the best way to perform this update. Can anyone suggest another way of doing this that would be faster and use less resources? Examples would be appreciated =)