Replicate SQL chages to Database DEFINITION - sql

Suppose I have two identical DataBases A and B, but with different Data. The tables, store procedures, etc are originally the same in both.
Now I start doing changes in the definition of DataBase A, like adding a new Table, deleting a Column of another table, after I finish all these changes , I would like to have "recorded" these changes to rerun them in DataBase B, so DataBase B definition will continue to be the same as DataBase A (the Data in both of them will still be different from A to B).
How can I record changes made in A and rerun them in B? Note that the changes I'm talking about are not in the Data but in the DataBase definition.

Related

Inserting a single row from different databases

To start off we have two databases. One called TOk and the other called test2. test2 is a backup of TOk. A situation occurred in which a single row was deleted accidentally from the TOk database in the hazards table. I just want to know if there is a way to copy that record single row to another database. HazID is the unique identifier in that particular table so would something like. Both databases reside on the same instance.
INSERT INTO Tok.hazard.dbo *
Select * From Test2.hazard.dbo
Where HazID=(the specific ID of the missing record)
Is this close?
Basically expect the record to be copied back into the live database.

copy data from one database to another in mssql while maintaining consistency

We need to push data from one database A to database B while maintaining consistency in current transactions happening in database B.
Problem:Data cannot be pushed directly to tables in database B because the customers might see inconsistent data,since it is join of 3-4 tables.
Approach:We have tried to create loading tables and loaded tables.We have created one synonym to point to loaded tables.Data will be pushed to loading tables first and once all data is pushed,we will copy that data to loaded tables and at that time synonym will be pointed to loading tables.Once all the data is copied to loaded tables,synonym will again point to loaded tables.
The problem with this approach is while switching synonym we need to drop synonym ad create same pointing to other(loading or loaded) table and at that time any incoming transaction might fail,if it could not find synonym.
Is there any other way to to cater this problem?

Database Replication after Data Load

I'm trying to understand the ramifications of database replication (SQL Server or Golden Gate) for situations where the source database is completely repopulated every night. To clarify, all existing tables are dropped and then the database is reloaded with new tables using same name along with all the data.
Based on my understanding i.e. that replication uses a transaction log... I would assume it will also repeat the process of dropping the tables instead of identifying the differences and just adding the new data. Is that correct?
You can set up the replication using OracleGoldenGate so that it will be doing what you want it to do.
the TRUNCATE TABLE command can be replicated or it can be ignored
the populating of the source table (INSERT/bulk operations) can be replicated or it can be ignored
if a row already exists (meaning a row with the same PK exists) on the target and you INSERT it on the source you can either UPDATE the target or DELETE the old one and INSERT the new, or ignore it
Database replication is based on the redo (transaction) log. Only particular events that appear on the source databases, which are logged can be replicated. But the whole replication engine can make some additional transformations as it is replicating the changes.

How to sense inserted or updated record in SQL tables via log table

I have to disjoint Database with some common tables, I can not do any modification on the tables of one database ( it is under use always, and I can not for example add a col to one table), but I need to sync these two databases every night. What is the best solution to do this job, for example is there any systemic stored procedure to sense any updated or inserted record in one table?
I should mention that, only one of these databases write in these data bases?
you can write some batch script to sync the tables every night, use some scheduler to start the script (or) i guess you can also use triggers

mysql: how do i make a copy of the entire database?

how do i make an exact duplicate copy of a database in mysql?
create database test1 from test ???????
if this is not possible, how do i copy a table from one database into another"?
One way to do it is taking a dump from the source db and importing it into another db, like this:
mysqldump src_db > src.sql
mysql dest_db < src.sql
You can't per say. You need to create the new database, create the tables and then do inserts i.e. insert into INSERT INTO newdatabase.table1 SELECT * FROM olddatabase.table1;
Alternately, you could do a full database dump to a sql file and then dump this file into a new database.
A third option (easiest really if you have it) is PhpMyAdmin's copy database function. It creates the new database, the tables and inserts the data all automatically.
mysqlhotcopy db_name /path/to/new_directory
Keep in mind that the users will be blocked from updating tables while they are being copied, since mysqlhotcopy locks them.
I don't know if mysqlhotcopy locks them all at once or one at a time. If it locks them all at once, then all users will be blocked until the copy completes.
If it locks them one at a time while users are modifying them, you have a risk of the tables getting out of sync with each other. Like this:
mysqlhotcopy locks table a, and begins copy of table a
client attaches to database and tries to update tables a and c. It is temporarily blocked because of lock on table a.
mysqlhotcopy completes copy, unlocks table a, locks table b, and begins copy of table b
client makes related updates to tables a and c.
mysqlhotcopy completes copy, unlocks table b, locks table c, and copies table c
The problem is that the copied version of table a is from before the client's modification, and the version of table c is from after the client's modification, which puts the backup
in an inconsistent state.
Update
I just looked at mysqlhotcopy (MySQL 4.1.9). It locks all the tables at once.