使用C#,SQL sqever从其他数据库的数据库表访问数据的最佳方法是什么 [英] What is the best way to access data from table of data base in other database using c# , Sql sqever

查看:106
本文介绍了使用C#,SQL sqever从其他数据库的数据库表访问数据的最佳方法是什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是我在同一台sql服务器中有2个数据库..我想访问第二个数据库表中的第一个数据库的表数据..这样做的最佳方法是什么??

Problem is i have 2 databases in same sql server..i want to access a table data of 1st database in 2nd database table..what''s the best way to do this.?

推荐答案

我不确定我是否正确理解了您的问题,但是如果您想(例如)连接来自同一SQL Server上不同数据库的两个表,则可以使用以下语法:
I am not sure if I understand your question correctly, but if you want to (for example) join two tables from different databases on the same SQL server you can use the following syntax:
SELECT * FROM database1.dbo.table1 CROSS JOIN database2.dbo.table2 ...



.dbo前面的名称.表示数据库...

希望这会有所帮助,
欢呼
Andy



the name in front of .dbo. indicates the database...

hope this helps,
cheers
Andy


如果数据库所在的SQL服务器与您可以使用链接服务器的SQL服务器不同,

将链接服务器添加到您的sqlserver,
并通过使用链接服务器的存储过程访问服务器,您已经添加了
或通过视图访问该链接服务器并加入您的主要数据
if DB''s are in different sql server than u can use linked server,

add a linked server to your sqlserver,
and access that server by a store procedure using linked server u have added
or access that linked server by a view and join your main data''s


这篇关于使用C#,SQL sqever从其他数据库的数据库表访问数据的最佳方法是什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆