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 2008 Forums
 Transact-SQL (2008)
 What's the smart way to use GUIDs?

Author  Topic 

KilpAr
Yak Posting Veteran

80 Posts

Posted - 2013-03-28 : 07:54:40
I have users (Salesmen) in ActiveDirectory and I think the only way I can identify them is using ObjectGUIDs. Now when I have the query to the linked server and receive all the info from there along with the GUIDs, I obviously need to make queries against that table. So I can have a query like
SELECT Orders FROM OrderTable WHERE Salesman =

what? The GUID? Am I supposed to type the whole 34-character string there everytime I set up a query? Or should I make a table that has the GUIDs and some autonumber ID to make kind of an alias for the GUID? Or how should I treat these?

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-03-28 : 08:29:10
If the uniqueness of the Salesman column is determined by a GUID, you would have to use the GUID in the where clause. Anything else (such as lastname + firstname) might give you incorrect results. There could be two Jane Doe's for example.

You could add an autoincrementing column (identity column) to the table where the Salesman informaton is kept and then use the value in that column in the where clause, but I can't say whether that is a good thing to do or not without knowing a lot more about your tables and queries.
Go to Top of Page

KilpAr
Yak Posting Veteran

80 Posts

Posted - 2013-03-28 : 08:38:16
quote:
Originally posted by James K

If the uniqueness of the Salesman column is determined by a GUID, you would have to use the GUID in the where clause. Anything else (such as lastname + firstname) might give you incorrect results. There could be two Jane Doe's for example.

You could add an autoincrementing column (identity column) to the table where the Salesman informaton is kept and then use the value in that column in the where clause, but I can't say whether that is a good thing to do or not without knowing a lot more about your tables and queries.



The salesman information is kept in a view - or more exactly - in ActiveDirectory, which is connected using a linked server and then queried to parse the view. I don't know if I know make a reliable autoincrementing column in a view and that's why I thought of using an extra table instead.

But yes, this chance of "double names" is exactly the problem here - and as we both know, a schoolbook example of what not to use as ID.
Go to Top of Page

ScottPletcher
Aged Yak Warrior

550 Posts

Posted - 2013-03-28 : 10:37:31
Typically companies assign salesmen unique numbers, which may be the equivalent of identity-based or may be manually assigned.

I would assign each unique salesman a unique number and use that.

We all know guids are a pain to work with; that's why most people avoid them whenever possible .
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-28 : 10:51:12
One way is to use custom generated sequence based on identity field


see example here

http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

KilpAr
Yak Posting Veteran

80 Posts

Posted - 2013-03-29 : 11:37:50
quote:
Originally posted by visakh16

One way is to use custom generated sequence based on identity field


see example here

http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





This was interesting to read and seems like I wasn't way off with my initial suggestion of an extra table.

Thanks!
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-29 : 14:03:35
quote:
Originally posted by KilpAr

quote:
Originally posted by visakh16

One way is to use custom generated sequence based on identity field


see example here

http://www.sqlteam.com/article/custom-auto-generated-sequences-with-sql-server

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/





This was interesting to read and seems like I wasn't way off with my initial suggestion of an extra table.

Thanks!


It doesnt need an extra table but just an extra column

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -