Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how can I use GUID datatype in SQL Server 2008?

I want to build an employees table using SQL SERVER 2008 , and in my table I want to have an ID for each employee .

I heared about GUID and I kind of understood that its a data type , But I couldn't use it

could you please show me the way to use it ...

by the way , lets say I want something like this :

CREATE TABLE Employees (
ID guid PRIMARY KEY,
Name NVARCHAR(50) NOT NULL
)

How can I do it ?? because I want to benefit from it , but I couldn't find out how to do that

like image 633
Mouayad Avatar asked Nov 04 '10 19:11

Mouayad


People also ask

What is the datatype for GUID SQL Server 2008?

What is a GUID? GUID is a 16 byte binary SQL Server data type that is globally unique across tables, databases, and servers. The term GUID stands for Globally Unique Identifier and it is used interchangeably with UNIQUEIDENTIFIER.

How do I add a GUID to a database?

-- If you want to generate a new Guid (uniqueidentifier) in SQL server the you can simply use the NEWID() function. -- This will return a new random uniqueidentifier e.g. You can directly use this with INSERT statement to insert new row in table.

Which datatype is used for assigning GUID?

The GUID data type is a 16 byte binary data type. This data type is used for the global identification of objects, programs, records, and so on. The important property of a GUID is that each value is globally unique. The value is generated by an algorithm, developed by Microsoft, which assures this uniqueness.

Does SQL support GUID?

There are two functions using which you can create GUIDs in SQL Server – NewID and NewSequentialID. And there's a data type – "uniqueidentifier" which can be used to store GUIDs. It stores a 16-btye binary value.


1 Answers

It's not called GUID in SQL Server. It's called uniqueidentifier

like image 142
Vidar Nordnes Avatar answered Oct 23 '22 11:10

Vidar Nordnes