I've deleted some records from a table in a SQL Server database. Now the ID's go from 101 to 1200. I want to delete the records again, but I want the ID's to go back to 102. Is there a way to do this in SQL Server?
相关问题
- sql execution latency when assign to a variable
- What is the best way to cache a table from a (SQL)
- php PDO::FETCH_ASSOC doesnt detect select after ba
- Bulk update SQL Server C#
- SQL to Parse a Key-Value String
相关文章
- Entity Framework 4.3.1 failing to create (/open) a
- Code for inserting data into SQL Server database u
- Max Size of SQL Server Auto-Identity Field
- how to set H2 primary key id to auto_increment?
- Delete Every Alternate Row in SQL
- Linux based PHP install connecting to MsSQL Server
- SQL Azure Reset autoincrement
- How do we alias a Sql Server instance name used in
Try this:
I figured it out. It's:
if number=0 then in the next insert the auto increment field will contain value 1
if number=101 then in the next insert the auto increment field will contain value 102
Some additional info... May be useful to you
Before giving auto increment
number
in above query, you have to make sure your existing table's auto increment column contain values less thatnumber
.To get the maximum value of a column(column_name) from a table(table1), you can use following query
Based on the accepted answer, for those who encountered a similar issue, with full schema qualification:
(
[MyDataBase].[MySchemaName].[MyTable]
)... results in an error, you need to be in the context of that DBThat is, the following will throw an error:
Enclose the fully-qualified table name with single quotes instead:
Delete and Reseed all the tables in a database.
Issue the following command to reseed mytable to start at 1:
Read about it in the Books on Line (BOL, SQL help). Also be careful that you don't have records higher than the seed you are setting.