Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Alias

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-03-11 : 11:30:04
Hello,

I am creating a internal URL alias on my application similar to TinyUrl: http://tinyurl.com/a21gs

I was thinking in creating a table as follows:
AliasId
AliasUrl
SourceUrl

For example:
http://www.mywebsite.com/document/show/ade59599-8686-49ab-b64d-35be3957e6aa would become: http://mywebsite.com/a1

I believe in most applications I will only need a 2 characters length:
26 letters + 10 digits = 2 ^ 36 combinations = 68 719 476 736

Or maybe I could even change it to:
AliasKey, SourceUrl

Since AliasKey is always unique it can be used as PK and then I just add the basic url: http://mywebsite.com/ + AliasKey

1. Is this possible?
2. How can I generate a 2 character string using 2 of the 26 letters + 10 digits and be sure that does not exist in the table yet?

Thanks,
Miguel

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-11 : 11:36:28
Learn your math.
26 + 10 combinations (36 combinations) for two positions are 36 * 36 total combinations which is 1296 combinations, not 68,719,476,736.

What you have thought of, is to have an 2-combination switch for 36 positions. 2^36 is 68,719,476,736


E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-03-11 : 12:01:18
Obviously ... I was calculating nAp and instead of making n^p I made p^n ...
That was a mistake when writing fast my post ... Shame ...I am a Math College teacher ... lol
So I will increase the length and may drop a few more characters there ...

Anyway, math is not really the problem.

The problem is:
- How to generate a random key and be sure that it is unique.
Should this be made on SQL or on C# code?
- And should I use the first or the second approach for the table?

Forgive my mistake :-)

Thank You,
Miguel
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-03-11 : 14:54:39
Should I use the table:
AliasId (Guid - PK), ResourceUrl (nvarchar), AliasKey (nvarchar)

Where AliasKey must be 4 characters length and unique.

OR:
AliasKey (nvarchar - PK), ResourceUrl (nvarchar)

Where AliasKey must be 4 characters length and unique.

Which approach should I use?
And how can assure that AliasKey is unique?

Thanks,
Miguel

Thanks,
Miguek
Go to Top of Page
   

- Advertisement -