如何在SQL Server中使用不同数据库的表(How to use table of different database in SQL Server)

编程入门 行业动态 更新时间:2024-10-19 10:19:59
如何在SQL Server中使用不同数据库的表(How to use table of different database in SQL Server)

我必须将一些表(16个表)传输到另一个数据库,并且有一些使用这些表的存储过程(200个表)。

将存储过程传输到另一个数据库不是首选。

对于我的情况:

dbA包含sp_xyz存储过程, tableB和tableC表。

和sp_xyz内容可以是:

SELECT A.column1, B.column2 FROM tableB A JOIN tableC B ON A.fk_b_id = B.id

我们想将tableC传输到dbB。 所以我应该如何改变这个最小变化。

I have to transport some tables(16 tables) to another database and there are a number of stored procedures(200 tables) which use these tables.

Transporting stored procedures to another database is not preferred.

For my case:

dbA contains sp_xyz stored procedure, tableB and tableC tables.

and content of sp_xyz can be :

SELECT A.column1, B.column2 FROM tableB A JOIN tableC B ON A.fk_b_id = B.id

we want to transport tableC to dbB. So how should I change this sp with minimum change.

最满意答案

你想在其他数据库中使用Table,而不是在sql server中使用。

如果该数据库在同一台服务器上工作

Select * from [DBName].[Schema].[Table]

如果在antoher服务器中的数据库比,为这个屁股sql服务器作为链接服务器在你的sql服务器

Select * from [DBServer].[DBName].[Schema].[Table]

Schemcaname - 默认在sql server中用您的schemca替换为“dbo”

If you want to use a table in another database then you can do like this in sql server when the database is on same server:

Select * from [DBName].[Schema].[Table]

If the database is in another server, specify the linked server name too:

Select * from [DBServer].[DBName].[Schema].[Table]

Schema name - replace by your schema which is "dbo" by default in sql server.

更多推荐

本文发布于:2023-08-03 13:28:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1390702.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:数据库   如何在   SQL   Server   table

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!