>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:
create table myTable ;
(myPK int not null IDENTITY primary key, myField varchar(10))
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