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
 General SQL Server Forums
 New to SQL Server Programming
 Guid

Author  Topic 

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-03-12 : 10:16:47
Hello,

I have two tables Articles and Documents where the PKs are ArticleID and DocumentID both Guids

On a third table, Alias, I have two columns:
Int AliasId
NVarChar Source

Source can be an url (Contact/User1) or a Guid (In text format).

Can I insert in Source Guids coming from Articles and from Documents tables?

Thanks,
Miguel

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2009-03-12 : 10:52:37
Yes you can insert GUIDs from one table into another. You need to give details as to how you want them copied - e.g one off insert / copy as soon as one created etc.
Also if you generate a CREATE table script for each table - it will speed answer.
Go to Top of Page

shapper
Constraint Violating Yak Guru

450 Posts

Posted - 2009-03-12 : 11:02:25
quote:
Originally posted by darkdusky

Yes you can insert GUIDs from one table into another.



My problem was since I am inserting Guids from Articles and from Documentos into Alias table I might have the risk of having an equal Guid in Articles and Documents that would then create a problem when adding both to Alias table ...
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-03-12 : 11:40:20
A guid created with NEWID() is guarateed to be unique within same database. Possible same server as well.
I have however come across a duplicate guid from two separate machines.



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

darkdusky
Aged Yak Warrior

591 Posts

Posted - 2009-03-12 : 12:02:30
GUIDs have a performance impact especially on indexing:
http://www.sql-server-performance.com/articles/per/guid_performance_p1.aspx

If you generated your own custom sequential number in each table e.g
for Articles: A0000001,A0000002 ... etc, for Documents: D0000001,D0000002 .. etc. they will never collide and if you copy to the alias table they will be meaningful. And they will mean the indexed field could be used in searches e.g Select * from alias where Id like 'A%'

http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server
Go to Top of Page
   

- Advertisement -