I have a table in SQL Server called Personal_Info
. Tthis table has a column called Vol_ID
and the (Is Identity)
property is Yes
.
Now I inserted about 175568 rows as a test. And then I deleted about 568 rows, BUT when I insert the data again the column Vol_ID
start from 175569 not from 175001.
I want to insert the data and let the column Vol_ID
start from the last number in it. For example if the last row is 15, the next row should be start from 16, even if I already inserted but I delete it.
I need a stored procedure or a trigger that can force the insert operation to filled that missing id's, check the last exist row and if there is missing id's after the exist one then filled it.
I have this procedure to make the insertion
USE [VolunteersAffairs]
go
/****** Object: StoredProcedure [dbo].[AddVolunteer] Script Date: 05/02/2014 21:12:36 ******/
SET ansi_nulls ON
go
SET quoted_identifier ON
go
ALTER PROCEDURE [dbo].[Addvolunteer] @Vol_Name NVARCHAR(255),
@Vol_Zone NVARCHAR(255),
@vol_street NVARCHAR(255),
@Vol_Sex INT,
@Vol_Date_of_Birth DATE,
@Vol_Home_Phone INT,
@Vol_Work_Phone INT,
@Vol_Mobile1 INT,
@Vol_Mobile2 INT,
@Vol_Email NVARCHAR(255),
@Vol_Job NVARCHAR(255),
@Vol_Affiliation NVARCHAR(255),
@vol_Education INT,
@vol_Education_Place NVARCHAR(255),
@vol_Education_Department NVARCHAR(255),
@vol_Interesting INT,
@vol_Notes NVARCHAR(255),
@Team_ID INT
AS
INSERT INTO personal_info
(vol_name,
vol_zone,
vol_street,
vol_sex,
vol_date_of_birth,
vol_home_phone,
vol_work_phone,
vol_mobile1,
vol_mobile2,
vol_email,
vol_job,
vol_affiliation,
vol_education,
vol_education_place,
vol_education_department,
vol_interesting,
team_id,
vol_notes)
VALUES (@Vol_Name,
@Vol_Zone,
@vol_street,
@Vol_Sex,
@Vol_Date_of_Birth,
@Vol_Home_Phone,
@Vol_Work_Phone,
@Vol_Mobile1,
@Vol_Mobile2,
@Vol_Email,
@Vol_Job,
@Vol_Affiliation,
@vol_Education,
@vol_Education_Place,
@vol_Education_Department,
@vol_Interesting,
@Team_ID,
@vol_Notes)
Please Help me to write the missing id's