Search This Blog

Thursday, November 8, 2007

Synonym

Synonyms can be called as pointers used to call the objects or in simple word it is a alias named for objects like Tables,Views,Procedures & Functions.

Now synonyms are really useful where in the objects referrred can exist on same server in different database or different schema or even on a different server.

Syntax of how to create a synonym
Create Synonym Employee_Syn for ...Tablename

Using a synonym
Select * from Employee_Syn

Rank Function

As the name suggests it does the same of displaying rank againt each record.

You might wonder ROWNUM also does the same function then why do i need one more function of the same feature.Answer is Rank provides the same Serial number if two records have the same value.Lets understand the same by means of a example.

Students Table
StudentID
Student Name
Total Marks

Records
S1, "Mark",450
S2, "Lloyd",400
S3, "Rob", 327
S4, "Henry",450
S5, "Peter",327

Query using Rank
Select StudentID,
FirstName,
TotalMarks,
Rank() Over (Order by TotalMarks desc)
From Students

Output
S1, "Mark",450,1
S4, "Henry",450,1
S2, "Lloyd",400,2
S3, "Rob", 327,3
S5, "Peter",327,5