Web Listing 1: Code to Create Image Tables /*============================================================== Table: dbo.IMAGE ==============================================================*/ create table dbo.IMAGE ( ImageID int PRIMARY KEY, ImageName varchar(30) not null, ImageFile varchar(30) not null ) GO -- -- add the primary key (pkey is automatically indexed) -- ALTER TABLE dbo. IMAGE ADD CONSTRAINT PK_ ImagePRIMARY KEY CLUSTERED (ImageID) GO /*============================================================== Table: dbo.KEYWORD ==============================================================*/ create table dbo.KEYWORD ( KeywordID int identity(1 , 1) NOT FOR REPLICATION, KeywordDscr varchar(30) not null ) GO -- -- add the primary key (pkey is automatically indexed) -- ALTER TABLE dbo.KEYWORD ADD CONSTRAINT PK_Keyword PRIMARY KEY NONCLUSTERED (KeywordID) GO -- -- add a unique clustering index (unique to avoid duplicate keywords) -- CREATE UNIQUE CLUSTERED INDEX idu_Keyword_Dscr ON dbo.Keyword (KeywordDscr) WITH IGNORE_DUP_KEY, PAD_INDEX, FILLFACTOR = 90 GO /*============================================================== Table: dbo.IMAGEKEYWORD ==============================================================*/ create table dbo.IMAGEKEYWORD ( ImageKeywordID int identity(1,1) NOT FOR REPLICATION, ImageID int not null, KeywordID int not null, ) GO -- -- add the primary key (pkey is automatically indexed) -- ALTER TABLE dbo.IMAGEKEYWORD ADD CONSTRAINT PK_ImageKeyword PRIMARY KEY NONCLUSTERED (ImageKeywordID) GO -- -- add a clustering index -- CREATE CLUSTERED INDEX idc_imagekeyword ON dbo.IMAGEKEYWORD (ImageID, KeywordID) GO -- -- add a normal index -- CREATE INDEX idx_imagekeywd_imageID ON dbo.IMAGEKEYWORD (KeywordID ) GO /*------------------------------------------------------------------- add the foreign key constraints -------------------------------------------------------------------*/ ALTER TABLE dbo.IMAGEKEYWORD ADD CONSTRAINT fk_ImageKeywd2Image FOREIGN KEY (ImageID) REFERENCES dbo.IMAGE (ImageID) GO ALTER TABLE dbo.IMAGEKEYWORD ADD CONSTRAINT fk_ImageKeywd2Keywd FOREIGN KEY (KeywordID) REFERENCES dbo.KEYWORD (KeywordID) GO