Friday, June 8, 2007

Synonym (SQL 2005)

This a new feature in SQL 2005. It provides aliasing at the database level. It is similar to the 'AS' command that provides aliasing at the query level. (See article http://builder.com.com/5100-6388_.html?part=rss&tag=feed&subj=bldr)

Example:

USE Inventory

GO

CREATE SYNONYM SalesHistory

FOR SalesData.dbo.SalesHistory;

GO

Wednesday, June 6, 2007

RIGHT JOIN

The same as a left join but the table order is changed.

Returns all the rows from the second table, even if there are no matches in the first table.

This is a good means of find elements in one table but not in another.

Syntax:

SELECT field1, field2, field3, ... fieldN
FROM first_table
RIGHT JOIN second_table
ON first_table.keyfield = second_table.foreign_keyfield;

(see http://www.w3schools.com/sql/sql_join.asp)