Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Data type for Primary Key
Message
De
21/05/2003 04:59:33
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Client/serveur
Divers
Thread ID:
00790773
Message ID:
00790950
Vues:
19
This message has been marked as the solution to the initial question of the thread.
>Hello !
>I'm working on moving old DBase application into SQL Server using VFP8. I'm wondering if somebody knows what's the best type of data for Primary key in SQL Server. I usually use SYS(2015) in VFP. Is Uniqueidentifier type sort of analog of it ?
>Thanks in advance.
>Mariam

There is no exact counterpart of sys(2015) I think (and it's only unique for a given computer).
Your assumption on uniqueidentifier analogy is right. IMHO it's the best datatype in SQL server for a unique column (such as row identifier - primary key).

In SQL server you could use identity or uniqueidentifier columns as surrogate primary key columns.
Identity column is like VFP8's autoinc column and is not guaranteed to be unique at all times.
OTOH uniquidentifier is guaranteed to be universally unique (not 100% in theory but in practice).

ie:
*identity
create table myTable ;
 (myPK int not null IDENTITY primary key, myField varchar(10))

*uniqueidentifier

create table myTable ;
  (myPk uniqueidentifier ;
       not null ;
       ROWGUIDCOL ;
       default newid() ;
       primary key, ;
       myField varChar(10))
Note that :
It's 'primary key' constraint ensuring the uniqueness not the datatype or being identity/uniqueidentifier.
Unlike Identity, uniqueidentifier is not auto generated, hence 'default newid()' function is used to get a GUID.
ROWGUIDCOL (and IDENTITYCOL) could occur only once in a table and could be used as a columnname w/o a need to know actual column name. ie:
select ROWGUIDCOL from myTable
(Actual column name is myPK).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform