This question already has answers here:
SQL Server cross database alias
(2 answers)
Closed 8 years ago.
I have 2 databases (db1, db2) - SQL Server.
And each database use another in stored procedures, functions
in db1:
select * from db2.dbo.users
in db2:
select * from db1.dbo.items
The problem is that there is hard coded db names in procedures.
Now we want to add databases db1_test, db2_test on this server.
What is the easiest way to resolve this problem without updating all procedures, functions with new database names.
Thanks!
You can have it on a separate instance or server. Test and prod database shouldn't reside on the same box.. let alone same database. In an ideal world that is.
Related
This question already exists:
Migrating schema, table, data, function, stored procedure from MS SQL to PostgreSQL [closed]
Closed 2 years ago.
Is there any open source tool available to migrate schema, tables, data, function, stored procedure from MS SQL to PostgreSQL?
There is a tool called full convert using which you can migrate across different databases.
You need to take the dump from MS SQL and then you can migrate it to psql.
This question already has an answer here:
How do I generate scripts for all tables with single stroke in SQL Server 2000? [closed]
(1 answer)
Closed 3 years ago.
I have a database with many tables that have been periodically updated over the years (not by me). I would like to make CREATE TABLE scripts for all of the tables.
It appears Script table as... only works on a single table at a time. Is there a way to script out all of the tables in a database?
In SSMS, Right Click the Database, go to Tasks -> Generate Scripts.
In the second window, select Select specific database objects and tick Tables:
Choose where you want the results to to go, File, Clipboard or a new Query Window
Check all the settings are correct
Finish. Consume your file/clipboard.
This question already has answers here:
Is there any way to generate database scripts from a SQL query in SQL Server?
(2 answers)
Closed 4 years ago.
I am presently using SQL Server 2008. I want to move the entire applications and database to SQL Server 2016 without data. i.e. I don't want to copy the entire data but I need all the tables and everything from the previous server. Can please anyone help me with this?
You'll want to script out each database. To do so:
right click on the database
tasks
generate scripts
using the wizard, choose all the data objects you want (tables, views, etc.) or all of them
save to a location
open the file from that location
boom, there is your code set up all your tables, etc. for your database!
Just repeat for each database you want to 'copy'. Just remember (as requested) each table will have no data in it. Alternatively you can backup and restore each database and then truncate each table, that is probably a lot more work though.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Find a specific column entry in an unknown table in a database?
how to search Sql Server 2008 R2 stored procedures for a string?
Hello I'm trying to figure out a fairly complex SQL Server(2008 in 2000 compatibility) database. There are 3 columns in a table I'm particularly concerned with. I've searched the code of our application and it seems to make no direct usage of these 3 columns but I know somewhere in the database they are populated and used. So it must be in triggers, functions, and/or stored procedures.
What is the best way of figuring out where to look for the code that populates these 3 columns?
If you need to find database objects (e.g. tables, columns, triggers) by name - have a look at the FREE Red-Gate tool called SQL Search which does this - it searches your entire database for any kind of string(s).
It's a great must-have tool for any DBA or database developer - did I already mention it's absolutely FREE to use for any kind of use??
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Selecting data from two different servers in SQL Server
How can I join two tables, which are located two different SQL Server instances, in one query?
The best way I can think of to accomplish this is via sp_addlinkedserver. You need to make sure that whatever account you use to add the link (via sp_addlinkedsrvlogin) has permissions to the table you're joining, but then once the link is established, you can call the server by name, i.e.:
SELECT *
FROM server1table
INNER JOIN server2.database.dbo.server2table ON .....
You can create a linked server and reference the table in the other instance using its fully qualified Server.Catalog.Schema.Table name.
If you are using SQL Server try Linked Server