How can I enable the automatic numbers of access and SQL Server databases to be sorted again from 1?

Source: Internet
Author: User

After an automatic number field in the database table is used for a period of time, it does not start from 1 when all the data is deleted, but adds 1 to the previous value or adds the set step value, such as access, MySQL, and MSSQL. How can I enable automatic numbering from 1 after data is cleared? Sometimes I want the Access database to automatically increase the number of the specified step at a time instead of starting from 1, or starting from the specified value? The following methods are provided for reference:
1. Access Database
1. If you want to retain data
1.1 you can delete the automatic number field and then add an automatic number field.
1.2 (1). Create a query in access.
(2) Right-click the design query interface and select the SQL view.
(3) enter the following SQL statement to execute
Alter table table name
Alter column [automatically numbered field names] counter (initial value, step value)
For example, if you want to set the ID of the automatically numbered field in the TT table to start from 1, you can: alter table tt alter column ID counter (1, 1)
To enable the auto-numbered field ID of the TT table to increase by 10 each time starting from 100, you can: alter table tt alter column ID counter (100, 10)
Note: The 1.2 method can be executed when a database is just created, cleared, or has data. After the DDL statement is executed by default, if the ID is set as the primary key, it will be canceled, if there can be duplicate IDs in the database, you can change the primary key setting to alter column [automatically numbered field name] counter if you want to keep the primary key setting after execution.
(Initial Value, step value) primary key (but the specified initial value must not be the same as the existing ID value)
2. If you do not want to retain the data, you just want to restore the automatic number from 1.
2.1 copy the original database table and only copy the data structure.
2.2. After deleting all the data, select a tool, select a database utility, and click compress and restore the database.
2.3 After deleting all data, change the automatic number field to "not automatically numbered", save it, and then change it to "automatically numbered ".
2. When data is retained in the MSSQL database and MySQL database, see "1.1". When data is not retained, run the following command: truncate table name to quickly clear the entire table data so that the automatic number starts at the beginning.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.