You are on page 1of 1

SQL Server Outer JOIN Example

SELECT NAME, (SELECT [DESC] FROM P


LEFT OUTER JOIN PRODUCTDESC
ON PRODUCT.PDID = PRODUCTDESC.PDID)
FROM PRODUCT P
INNER JOIN - Match rows between the two tables specified in the INNER JOIN state
ment based on one or more columns having matching data. Preferably the join is
based on referential integrity enforcing the relationship between the tables to
ensure data integrity.
o
Just to add a little commentary to the basic definitions above, in gener
al the INNER JOIN option is considered to be the most common join needed in appl
ications and/or queries. Although that is the case in some environments, it is
really dependent on the database design, referential integrity and data needed f
or the application. As such, please take the time to understand the data being
requested then select the proper join option.
o
Although most join logic is based on matching values between the two col
umns specified, it is possible to also include logic using greater than, less th
an, not equals, etc.
What is normalization? - Well a relational database is basically composed of tab
les that contain related data. So the Process of organizing this data into table
s is actually referred to as normalization.
What is a Stored Procedure? - Its nothing but a set of T-SQL statements combined
to perform a single task of several tasks. Its basically like a Macro so when y
ou invoke the Stored procedure, you actually run a set of statements.
Can you give an example of Stored Procedure? - sp_helpdb , sp_who2, sp_renamedb
are a set of system defined stored procedures. We can also have user defined sto
red procedures which can be called in similar way.
What is a trigger? - Triggers are basically used to implement business rules. Tr
iggers is also similar to stored procedures. The difference is that it can be ac
tivated when data is added or edited or deleted from a table in a database.
What is a view? - If we have several tables in a db and we want to view only spe
cific columns from specific tables we can go for views. It would also suffice th
e needs of security some times allowing specfic users to see only specific colum
ns based on the permission that we can configure on the view. Views also reduce
the effort that is required for writing queries to access specific columns every
time.
What is an Index? - When queries are run against a db, an index on that db basic
ally helps in the way the data is sorted to process the query for faster and dat
a retrievals are much faster when we have an index.
What are the types of indexes available with SQL Server? - There are basically t
wo types of indexes that we use with the SQL Server. Clustered and the Non-Clust
ered.
What is the basic difference between clustered and a non-clustered index? - The
difference is that, Clustered index is unique for any given table and we can hav
e only one clustered index on a table. The leaf level of a clustered index is th
e actual data and the data is resorted in case of clustered index. Whereas in ca
se of non-clustered index the leaf level is actually a pointer to the data in ro
ws so we can have as many non-clustered indexes as we can on the db.
What are cursors? - Well cursors help us to do an operation on a set of data tha
t we retreive by commands such as Select columns from table. For example : If we
have duplicate records in a table we can remove it by declaring a cursor which
would check the records during retreival one by one and remove rows which have d
uplicate values.
When do we use the UPDATE_STATISTICS command? - This command is basically used w
hen we do a large processing of data. If we do a large amount of deletions any m
odification or Bulk Copy into the tables, we need to basically update the indexe
s to take these changes into account. UPDATE_STATISTICS updates the indexes on t
hese tables accordingly.

You might also like