Access tutorials How to set automatic numbering to start with 1 sorting

Source: Internet
Author: User
Tags mssql table name access database mysql database

The specific implementation methods are as follows:

Method One:

Delete the Automatically numbered field, and then build the same AutoNumber field.

Method Two:

Automatic numbering is always increased (plus 1 each time), you add a record of its number will be in front of the base plus 1 (delete also count), if you number 1 is deleted, you want to start from 1, you can open the Access database, select Tools, and then select Database Utilities, Click the Compress and Repair database, so that's OK.

Method Three:

1. Create a new query in Access.

2, change the view to SQL view.

3, input 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, numbering starts from 1001.

Automatically numbered fields in a database table after a period of time, the data deleted all the new 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.

How do I get the data to be emptied and the AutoNumber starts at 1? Sometimes you want the Access database AutoNumber to start at 1 instead of starting with the value you specified, or to have access automatically number the specified step at a time? The following methods are available for reference:

For an Access database

1, want to retain the data

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

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

(2), in the design of the query interface right key to select the SQL view.

(3), enter the following SQL statement, execute

Alter Table Name

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

For example: Want the TT table AutoNumber field ID starting from 1, you can: Alter TABLE TT alter COLUMN ID COUNTER (1, 1)

To have the TT table AutoNumber field ID start at 100, each time by 10, you can: ALTER TABLE TT alter COLUMN ID COUNTER (100, 10)

Note: 1.2 Methods, can be performed when a database is newly built, emptied, or has data, and after the default execution of the DDL statement, if the ID is set as the primary key will be canceled, and if there is a value in the database that can duplicate the ID, there is still a primary key setting to Alter COLUMN [AutoNumber field name] COUNTER (initial value, step value) primary key (but specifying an initial value must not be the same as an existing ID value)

2, do not want to retain data, just want to restore the automatic numbering starting from 1

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

2.2, delete all the data, select the tool, and then select the Database utility, click the compression and Repair database.

2.3, delete all the data, the automatic numbering field instead of automatically numbered, save, and then changed to automatic numbering

MSSQL database, MySQL database to retain data can see 1.1, do not retain the data can be performed: TRUNCATE table name, you can quickly empty the entire table data so that the initial start of 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.