Previous | Table of Contents | Next |
Q What are the benefits to using ANSI or old style join syntax?
A The ANSI syntax can prevent you from making a simple mistake. You cannot accidentally create a cross join when you wanted an inner join, as you can do with the old style syntax. ANSI style syntax makes the relationships between tables easier to understand because it is explicitly spelled out for someone viewing the code. Also, it requires you to specify join keys together with the tables to which they belong (instead of separately, like with the old style). Finally, the ANSI join syntax is defined in the ANSI SQL standard. If standards compliance is important to you and your company, this style is guaranteed to be supported by MS SQL Server in future releases.
The old style syntax is less verbose than the ANSI style. It is more portable between RDBMSs because more of them recognize the old style. If you are using a combination of MS 6.0 and 6.5 servers, the old style syntax will work on both, but the ANSI syntax wont. The old style syntax is also more recognizable by a wider range of people in the industry (it has been around longer), so you will have an easier time getting help if you use it.
There is no performance benefit to using one or the other join syntax.
Q Does the order of the tables in the FROM clause affect performance?
A The short answer is No. MS SQL 6.5 was improved to deal with multitable queries in a better way than ever before. In previous versions, some queries that referenced over four tables could, in rare cases, miss a possibility for better join performance.
Q The ER diagram indicates a one-to-many relationship, and a one-to-one, but how about one to zero or more or a one to zero or one relationship? Arent these different?
A Some diagrams do consider these types of relationships and use zero to indicate them. Others lump these relationships in with many. For example, authors has a one-to-many relationship with titleauthor which is really a one to zero or more relationship. Diagrams that present this information do, in fact, present clearer images of the data relationships between tables.
Q Do the columns composing the common key need to have the same name?
A No, although they frequently do. It can be confusing when a customer number is called cust_num in the invoice table and cust_id in the customer table.
Q Do joins need to use the equals sign?
A No. You can join tables on any mathematical operator (<, >, <>, and so on). This can lead to some bizarre results. For example, what would you get if you asked for all the rows in titles where the title_id doesnt match the title_id in salesa lot of useless output! Still, these operators are used in some unusual circumstances.
The Workshop provides quiz questions to help you solidify your understanding of the material covered, as well as exercises to provide you with experience in using what youve learned. Try to understand the quiz and exercise answers before continuing on to the next days lesson. Answers are provided in the appendix.
Previous | Table of Contents | Next |