Home Forums SQL Server 7,2000 SQL Server Newbies How to use unique identifier column where clause of SQL Server 2000? RE: How to use unique identifier column where clause of SQL Server 2000?

  • I could not replicate your problem. I tried the following:

    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[Table1]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

    drop table [dbo].[Table1]

    GO

    CREATE TABLE [dbo].[Table1] (

    [pk] uniqueidentifier ROWGUIDCOL NOT NULL,

    [ln_no] [int] NULL

    ) ON [PRIMARY]

    GO

    ALTER TABLE [dbo].[Table1] WITH NOCHECK ADD

    CONSTRAINT [PK_Table1] PRIMARY KEY CLUSTERED

    (

    [pk]

    ) ON [PRIMARY]

    GO

    ALTER TABLE [dbo].[Table1] ADD

    CONSTRAINT [DF_Table1_pk] DEFAULT (newid()) FOR [pk]

    GO

    INSERT INTO Table1 (ln_no) VALUES (1)

    --Viewing the record in Enterprise Manager -> Tables -> Open Table -> All Rows:

    --the uniqueidentifier column is stored as

    {2F240FEA-0116-4915-9382-CFA4B97B9297} --NOTE curly braces {} !

    --whereas the query analyzer displays

    2F240FEA-0116-4915-9382-CFA4B97B9297 -- NO braces

    --1. From Query Analyzer, BOTH statements, with or without braces, WORK

    INSERT INTO Table1 (ln_no) values (1)

    SELECT * FROM Table1 WHERE pk = '{2F240FEA-0116-4915-9382-CFA4B97B9297}'

    SELECT * FROM Table1 WHERE pk = '2F240FEA-0116-4915-9382-CFA4B97B9297'

    pk ln_no

    2F240FEA-0116-4915-9382-CFA4B97B9297 1

    --2. Checking off IsRowGuid produces the same results

    INSERT INTO Table1 (ln_no) values (2)

    SELECT * FROM Table1 WHERE pk = '{707A6054-A363-4263-8CB7-F0776A518DA8}'

    SELECT * FROM Table1 WHERE pk = '707A6054-A363-4263-8CB7-F0776A518DA8'

    pk ln_no

    707A6054-A363-4263-8CB7-F0776A518DA8 2

    --Removing the default NEWID() property and entering it explicitly STILL WORKS

    INSERT INTO Table1 (pk, ln_no) Select NEWID(), 3

    SELECT * FROM Table1 WHERE pk = '{DE269F48-45DC-4BBB-8FD7-9A474E2906D6}'

    SELECT * FROM Table1 WHERE pk = 'DE269F48-45DC-4BBB-8FD7-9A474E2906D6'

    pk ln_no

    DE269F48-45DC-4BBB-8FD7-9A474E2906D6 3

    Tp help ypu further, you have to suly more info. Script your table and insert values.