-
what is ROWGUIDCOL DEFAULT function
Hi all:
I read a sql book, and part of the code is "ProductCategoryID UNIQUEIDENTIFIER NOT NULL
ROWGUIDCOL DEFAULT (NEWID()) PRIMARY KEY NONCLUSTERED"
I don't understand what the purpose of the code"ROWGUIDCOL DEFAULT (NEWID()) PRIMARY KEY NONCLUSTERED"
any idea?
Thank
________
HERO CBZ
Last edited by sql; 03-06-2011 at 01:24 AM.
-
--you can query the ROWGUIDCOL instead of querying the actual column name. example
create table table1 (ProductCategoryID UNIQUEIDENTIFIER NOT NULL ROWGUIDCOL DEFAULT NEWID() PRIMARY KEY NONCLUSTERED, name varchar(100))
create table table2 (ProductCategoryID UNIQUEIDENTIFIER NOT NULL DEFAULT NEWID() PRIMARY KEY NONCLUSTERED, name varchar(100))
insert into table1 (name) select 'MAK'
insert into table1 (name) select 'MAK2'
insert into table1 (name) select 'MAK3'
insert into table1 (name) select 'MAK4'
insert into table2 (name) select 'MAK'
insert into table2 (name) select 'MAK2'
insert into table2 (name) select 'MAK3'
insert into table2 (name) select 'MAK4'
select ROWGUIDCOL from table1
--result ProductCategoryID and all its values
--select ROWGUIDCOL from table2
--throws error
select OBJECTPROPERTY (object_id('table1'),'TableHasRowGuidCol')
-
HiMak:
Thank you for the reply, but when I call "select ROWGUIDCOL from table1" I got the following result, which are meanless for me.
2D8B721C-DC62-4F13-A2F7-66F569C422CA
5CCE75C5-67A6-40E9-8F38-E0EF7863EF38
C58381E3-D80A-4B74-A485-F830F5FFDD06
B611A691-9ACA-447D-803E-FB1AF2AF1586
________
OG KUSH PICTURES
Last edited by sql; 03-06-2011 at 01:25 AM.
-
Newid() Creates a unique value of type uniqueidentifier
It should be unique. That is it. Nothing to do with meaning ful or meaning less.
It will be useful when other columns have same data. Deleting duplicates is each with one unique column.
-
Hi mak:
I got it. thank you
________
Silversurfer Reviews
Last edited by sql; 03-06-2011 at 01:25 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|