How an Access database sets automatic numbering

Source: Internet
Author: User
Tags mssql

"E Mentor Network" Access in many cases will be used, and this software is quite practical, the following explains how to set the automatic numbering starting from 1 sorting problem

The specific implementation of the following actions:

method One:

Delete the auto-numbered field and build the same AutoNumber field.

Method Two:

automatic numbering is always increased (plus 1 each time), you add another record of its number will be added on the basis of 1 (delete also count), if your record numbered 1 is deleted, you want to start from 1, you can open the Access database, select Tools, and then select the Database utility, Click Compress and repair the database so that it is OK.

Method Three:

1. Create a new query in Access.

2. Change the view to SQL view.

3, enter in the inside

ALTER TABLE name ALTER COLUMN [AutoNumber field name] COUNTER (the initial value you want, 1)

For example:

alter TABLE [user] ALTER COLUMN [id] COUNTER (1001, 1)

4, after the operation, the number starts from 1001.

automatically numbered fields in database tables after a period of time, the data are all deleted and then added data will not start from 1, but then the previous value plus 1 or increase the set step value, Access,mysql,mssql and so on.

650) this.width=650; "src=" Http://183.61.143.148/group1/M00/02/46/tz2PlFQ3pdeiBNcDAAB6gnyibvo130.png "/>

How can I get the data emptied automatically numbering from 1 onwards? Sometimes you want an Access database to be automatically numbered without starting with 1, and you want to start with a specified value, or have Access automatically number the specified step at a time? The following methods are available for reference:

for an Access database

1, want to keep the data

1.1 You can delete the AutoNumber field, and then add an AutoNumber field

1.2 (1), create a new query in Access.

(2), right-click on the design query interface to select SQL view.

(3), enter the following SQL statement, execute

Alter Table Table name

Alter COLUMN [AutoNumber field name] COUNTER (initial value, step value)

For example: To get the TT table AutoNumber field ID starting with 1, you can: ALTER TABLE TT alter COLUMN ID COUNTER (1, 1)

to get the TT table AutoNumber field ID starting at 100, increase each time by 10, you can: ALTER TABLE TT alter COLUMN ID COUNTER (+)

Note: The 1.2 method can be executed when the database is just built, the database is emptied, or when there is data, after the default execution of the DDL statement, such as the ID is set to the primary key will be canceled, if there is a value in the database can be duplicate ID, you want to execute after the primary key setting can be changed to Alter COLUMN [AutoNumber field COUNTER (initial value, step value) primary key (but the specified initial value must not be the same as the ID value that already exists)

2, do not want to keep the data, just want to restore the automatic numbering from 1 onwards

2.1, copy the original database table, only the data structure can be copied.

2.2. After deleting all data, select Tools, select Database Utility, click Compress and Repair database.

2.3, after the deletion of all data, the automatic numbering field is changed to not automatically numbered, saved, and then changed to automatic numbering

MSSQL database, MySQL database to keep the data can be see 1.1, do not retain data can be executed: TRUNCATE TABLE name, you can quickly empty the entire table data to start the automatic numbering.

want to learn more Database Tutorials knowledge can be logged in E Mentor network.



This article is from the "Add Language" blog, please make sure to keep this source http://yuguotianqing.blog.51cto.com/9292883/1562626

How an Access database sets automatic numbering

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.