在sqlserver中连接表 [英] join tables in sqlserver

查看:67
本文介绍了在sqlserver中连接表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



你们中的任何一个人都可以告诉我如何加入太多的桌子,比如5张桌子,还请赐教我什么时候才能真正去视图。请为我提供几个关于它们的实时场景,因为我是SQL Server的新手



提前谢谢..

Hello Everybody,

Could any one of you please tell me how to join too many tables like 5 tables and also please enlighten me when do we actually go for VIEW. Kindly provide me couple of real time scenarios regarding them as I am newbie to SQL Server

Thanks in advance..

推荐答案

SQL Server加入示例 [ ^ ]


为了回答你问题的第一部分,我们根据我们建立的关系(根据规范化过程)加入表格。连接的意图应该能够使用键值(也可以是复合键)进行唯一标识。请记住连接使用已定义为PK的所有键,从而消除单个键可能会带来冗余数据。对于语法方面,alwys使用ANSI SQL-99格式: -



To answer the 1st part of your question, we join the tables depending upon the relationship that we have established ( as per the normalization process). The intention of the join should be able to identity unique using the key values( which can be composite key also).Keep in mind for join use all the keys that have been defined as PK, eliminating a single key could bring in redundant data. For the syntax side alwys use ANSI SQL-99 format :-

FROM <mytable>
JOIN <newtable> ON ..





使用的早期syantx(ANSI-SQL 92)是




The earlier syantx (ANSI-SQL 92) used to be

FROM <mytable>, <newtable>
WHERE <filter clause="">

SQL Server中''92 synatx的问题在于,它会创建一个交叉连接,这将共同影响查询的性能。



现在,对于视图: - 根据视图的定义,这些是存储其物理结构但不存储数据的逻辑结构,这意味着,创建时的视图仅包含数据的结构在我们查询视图时从实际表中获取(除非我们有一个物化视图)。



您可以随时查阅BOL以获取更多读数。

The problem with the ''92 synatx in SQL Server is that this would create an cross-join which would all together impact the performace of the query.

Now, for views :- As per the definition of view, these are logical structures that have their physical structure stored but not the data,meaning, a view when created contains only the structure the data is fetched from the actual tables when we query a view (unless we have a materialized view in place).

You, can always refer to the BOL for further readings.


请参阅以下链接,这对新手更有帮助像你一样..



http://www.w3schools。 com / sql / sql_join.asp [ ^ ]

http://www.w3schools.com/sql/sql_view.asp [ ^ ]
see the below link, which is more helpful for newbies like you..

http://www.w3schools.com/sql/sql_join.asp[^]
http://www.w3schools.com/sql/sql_view.asp[^]


这篇关于在sqlserver中连接表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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