Can I set category_id when creating a new category

  • Angus Lilburn-274633

    SSC Enthusiast

    Points: 153

    Hi,

    Is it possible to set category_id when creating a new category (in 2000) so it will be consistent accross all servers ? I can't find any allusion to it in the doc set.

    Many Thanks,

    A

  • Jens Süßmeyer

    SSC Enthusiast

    Points: 165

    WHat do you mean by category_id ? Is it some application specific number of your database ?

    HTH, Jens Suessmeyer.

    ---

    http://www.sqlserver2005.de

    ---

  • Angus Lilburn-274633

    SSC Enthusiast

    Points: 153

    Jens,

    Category_id as in the dbo.categories table

    Thanks,

    Angus

  • ram4tech

    Hall of Fame

    Points: 3140

    Angus,

    Here is an example of what you are looking for.

    CREATE TABLE dbo.Category (CategoryName VARCHAR(250), CategoryId AS CHECKSUM(CategoryName))

    ALTER TABLE dbo.Category ADD CONSTRAINT

       UK_CategoryName UNIQUE NONCLUSTERED (CategoryName)

    INSERT INTO dbo.Category (CategoryName) VALUES('Category 1')

    INSERT INTO dbo.Category (CategoryName) VALUES('Category 2')

    INSERT INTO dbo.Category (CategoryName) VALUES('Category 3')

    SELECT CategoryName, CategoryId FROM dbo.Category

    DROP TABLE dbo.Category

    HTH

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply