Identify relationships between multiple databases in SQL - sql

I am working on migrating an application from one server to the other. According to the connection string of this application, it is touching different databases. Meaning a view query in DB1 will touch a table in DB2. So while migrating this application, I constant get to see chain of 'Database unavailable' errors and every time I see such error, I have to migrate that specific database.
I am wondering, since we have ER diagrams to know about relationships between tables in a database, is there any way in SQL server to know the relationships/linkages between different DATABASES in a server? Are there any tool that does this?

Depending on number of databases you have, here would be a somehow quick way you can find that out (number of required search = number of available databases in the server):
Use 'SQL Search' application of Red-get
(https://www.red-gate.com/dynamic/products/sql-development/sql-search/download)
and search for the other database names one after another by selecting
your database of interest. Select all objects.
If you have metadata oriented design (a Stored Procedure looping through the names of different other Stored Procedures / Functions from different databases which are stored in a table as metadata and executing them with a wrapper Stored Procesure), then you will have make use of SQL Locator software (http://www.sqllocator.com/Downloads.html) to search for database names in SQL Table values.
Both of the above software are free.
You need to have SSMS (SQL Server Management Studio) installed to be able to use this application. After installation, ‘SQL Search’ will be directly available in your SSMS as an add-on.
SQL Locator can be directly used by providing the SQL Server name and your SQL Server credential.
Note:- The above steps will help you find out the referenced databases from a certain database within the same SQL Server. If you need to find out databases from Linked Server (I do not believe your question is asking that anyways), then you will have to smartly utilize the same above tools to find the external server reference by searching the external server name.

Related

Querying multiple database systems

Is it possible to query (or better, join) data from two different database systems? Let's say I have postgresql and SQL Server and I want to join a table from postgres to a table in SQL Server?
It doesn't matter which programming language.
What about utilizing a linked server? I use one to query an AS400 and join the results back to Microsoft SQL Server.
Quote from Microsoft documentation:
Configure a linked server to enable the SQL Server Database Engine to
execute commands against OLE DB data sources outside of the instance
of SQL Server. Typically linked servers are configured to enable the
Database Engine to execute a Transact-SQL statement that includes
tables in another instance of SQL Server, or another database product
such as Oracle. Many types OLE DB data sources can be configured as
linked servers, including Microsoft Access and Excel. Linked servers
offer the following advantages:
The ability to access data from outside of SQL Server.
The ability to issue distributed queries, updates, commands, and transactions on heterogeneous data sources across the enterprise.
The ability to address diverse data sources similarly.

SQL synchronize database between local and remote server

I've got 2 companies in different locations and the main server is at my office. The main server is working with a full version of SQL Server where the companies use SQL Server express version.
What is the best way to synchronize these SQL Server databases together that the main server have always the latest updates?
There are several technologies specifically for this type of scenario:
SQL Replication
Supports unidirectional or bidirectional synchronization
SSIS
Lets you define the mappings of the data, as well as transformations, and attach other code to the process easily
Linked-servers
Allows you to query databases and tables on remote servers as though they are part of the local database. Very easy to setup (just call exec sp_addlinkedserver) and once defined uses nothing but plain old SQL
If you want to do in an event (like button click), I would suggest Linked Server. Click here for a simple tutorial about how to create a linked server. After creating linked server, we can query it as follows:
select * from LinkedServerName.DatabaseName.SchemaName.TableName

Find difference between a table on many server

On my work we have a database on our server. But for some clients we implement on ther server the database. The problem comes when We change a table design on our server. We need to replicate that change manually on every client server.
Is there a way to see the difference of a table or all tables to know what tables or store procedures needs to be updated.
Here is a post on stackoverflow with list of tools to do a Schema compare: What is a free tool to compare two SQL Server Databases?
Additionally if you have VS 2010 Premium or Ultimate you can do a schema compare : http://msdn.microsoft.com/en-us/library/dd193250%28v=vs.100%29.aspx

Access remote Oracle from SQL Server in query only? (Crystal Reports command)

We have a peculiar challenge with overly-strict use restrictions, and I'm trying to find a way to accomplish it.
We have data in two locations, on different platforms. We are extracting data from application tables, and we aren't allowed to create our own views/procs/etc.
Is there a way to run a query into a remote Oracle DB from within an SQL Server query?
To further complicate issues, we have to make it run through a Crystal Reports database command.
We have ODBC connections defined at the BOXI platform (using Oracle ODBC for the Oracle connection).
I am hoping to use the SQL WITH clause to build in-memory views (for lack of a better term) to:
Initially extract some circuit IDs from the local SQL Server system,
Extract ticket numbers based on those circuit IDs, from the remote Oracle system,
Extract the core of our data from the SQL Server system, joined with the ticket data and return that to Crystal as a result dataset.
If we had our own space, this would be trivial.
BOXI doesn't let us do multiple-server universes.
You would need to some way to write and store connection strings, but it doesn't sound like you're able to do this.
If you can't make ANY changes to either source system, you might try creating an MS Access DB and using linked tables to bring in all the information you need and have your Crystal Report run from that. You would then only need to make sure that the machine you're running this on has the ODBC drivers to be able to connect, which are simple enough to configure.

Keeping database structure compatible between MS-Access and SQL Server

I'm working on a legacy project, written for the most part in Delphi 5 before it was upgraded to Delphi 2007. A lot has changed after this upgrade, except the database that's underneath. It still uses MS-Access for data storage.
Now we want to support SQL Server as an alternate database. Still just for single-user situations, although multi-user support will be a feature for the future. And although there won't be many migration problems (see below) when it needs to use a different database, keeping two database structures synchronized is a bit of a problem.
If I would create an SQL script to generate the SQL Server database then I would need a second script to keep the Access database up-to-date too. They don't speak the same dialect. (At least, not for our purposes.) So I need a way to maintain the database structure in a simple way, making sure it can generate both a valid SQL Server database as an Access database. I could write my own tool where I store the database structure inside an XML file, which combined with some smart code and ADOX would generate both database types.
But isn't there already a good tool that can do this?
Note: the application also uses ADO and all queries are just simple select statements. Although it has 50+ tables, there's one root "Document" table and the user selects one of the "documents" in this table. It then collects all records from all tables that are related to this document record and stores them in an in-memory structure. When the user saves the data, it just writes the document record and all changed data back to the database again. Basically, this read/write mechanism of documents is the only database interaction in the whole application. So using a different database is not a big problem.
We will drop the MS-Access database in the future but for now we have 4000 customers using this application. We first need to make sure the whole thing works with SQL Server and we need to continue to maintain the current code. As a result, we will have to support both databases for at least a year.
Take a look at the DB Explorer, there is a trial download too.
OR
Use migration wizard from MS Access to SQL Server
After development in Access (schema changes), use the wizard again.
Use a tool to compare SQL Server schemata.