修改网页的MSSQL语句

时间:2017-01-11 06:46:51

标签: asp.net sql-server content-management-system

我为我的网站创建了一个简单的数据库,它有一个内容管理系统,其中管理员可以添加最终存储在数据库中的项目。但是我注意到一个问题,每当我测试我的网站添加新项目时,id列在删除并再次添加新项目后继续增加。假设我的数据库中有8个固定项目,分别具有1-8个ID。我现在将创建第9个项目,它将给我id 9,但是当我删除它并创建一个新项目时,id号码将是10,依此类推。我想要发生的是id留在9号。

以下是我的数据概述图片:

enter image description here

如您所见,我的第9项ID为22,这不是我们想要的结果。

这是我的SQL声明:

        /****** Object:  Table [dbo].[guitarItem]    Script Date: 21/10/2016    15:20:18 ******/
   SET ANSI_NULLS ON
   GO
   SET QUOTED_IDENTIFIER ON
   GO
   SET ANSI_PADDING ON
   GO
   CREATE TABLE [dbo].[guitarItem](
      [id] [int] IDENTITY(1,1) NOT NULL,
      [type] [varchar](50) NOT NULL,
      [model] [varchar](50) NOT NULL,
      [price] [float] NOT NULL,
      [image1] [varchar](255) NULL,
      [image2] [varchar](255) NULL,
   PRIMARY KEY CLUSTERED 
   (
    [id] ASC
   )WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF,     ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO
   SET ANSI_PADDING OFF
    GO
   SET IDENTITY_INSERT [dbo].[guitarItem] ON
    INSERT [dbo].[guitarItem] ([id], [type], [model], [price], [image1], [image2]) VALUES (1, N'Ibanez', N'ARZ307', 9000.00 , N'../Images/Guitar Brands/Ibanez Guitars/ibanezARZ307.jpg', N'../Images/Guitar Brands/Ibanez Guitars/ibanezARZ307StandingPosition.png')
    INSERT [dbo].[guitarItem] ([id], [type], [model], [price], [image1], [image2]) VALUES (2, N'Ibanez', N'DT420TCR', 11000.00, N'../Images/Guitar Brands/Ibanez Guitars/ibanezDTR420TCR.jpg', N'../Images/Guitar Brands/Ibanez Guitars/ibanezDTR420TCRStandingPosition.png')
    INSERT [dbo].[guitarItem] ([id], [type], [model], [price], [image1], [image2])    VALUES (3, N'Ibanez', N'JBM100', 18000.00, N'../Images/Guitar Brands/Ibanez Guitars/ibanezJBM100.jpg', N'../Images/Guitar Brands/Ibanez Brands/ibanezJBM100StandingPosition.png')
   INSERT [dbo].[guitarItem] ([id], [type], [model], [price], [image1],   [image2]) VALUES (4, N'Ibanez', N'M8M', 13000.00, N'../Images/Guitar   Brands/Ibanez Guitars/ibanezM8M.png', N'../Images/Guitar Brands/Ibanez   Guitars/ibanezM8MStandingPosition.png')
  INSERT [dbo].[guitarItem] ([id], [type], [model], [price], [image1], [image2]) VALUES (5, N'Ibanez', N'RGAIX7FM', 15000.00, N'../Images/Guitar Brands/Ibanez Guitars/ibanezRGAIX7FM.jpg', N'../Images/Guitar Brands/Ibanez Guitars/ibanezRGAIX7FMStandingPosition.png')
    INSERT [dbo].[guitarItem] ([id], [type], [model], [price], [image1], [image2]) VALUES (6, N'Ibanez', N'JEM77P', 30000.00, N'../Images/Guitar Brands/Ibanez Guitars/ibanezJEM77P.jpg', N'../Images/Guitar Brands/Ibanez   Guitars/ibanezJEM77PStandingPosition.png')
   INSERT [dbo].[guitarItem] ([id], [type], [model], [price], [image1], [image2])    VALUES (7, N'Ibanez', N'AR325', 8000.00, N'../Images/Guitar Brands/Ibanez   Guitars/ibanezAR325.jpg', N'../Images/Guitar Brands/Ibanez  Guitars/ibanezAR325StandingPosition.png')
    INSERT [dbo].[guitarItem] ([id], [type], [model], [price], [image1], [image2])     VALUES (8, N'Ibanez', N'PGM3', 36000.00, N'../Images/Guitar Brands/Ibanez    Guitars/ibanezPGM3.jpg', N'../Images/Guitar Brands/Ibanez   Guitars/ibanezPGM3StandingPosition.png')


 SET IDENTITY_INSERT [dbo].[guitarItem] OFF