Automatically provide unique id in the database

后端 未结 3 555
無奈伤痛
無奈伤痛 2021-01-26 04:27

In my project i need to register a donor and I need the user to enter his information and the system registers him and generate a unique id to the donor.

3条回答
  •  北恋
    北恋 (楼主)
    2021-01-26 05:06

    Make a table with a field ID that has an index and has auto increment on.

    CREATE TABLE Persons
    (
    ID int NOT NULL AUTO_INCREMENT,
    LastName varchar(255) NOT NULL,
    FirstName varchar(255),
    Address varchar(255),
    City varchar(255),
    PRIMARY KEY (ID)
    )
    

    If you now add a new rule with MySQL you can leave the ID field empty, or just don't pass it like below

    INSERT INTO Persons(LastName, FirstName, Address, City) VALUES('Your firstname','lastname','adress','city')
    

提交回复
热议问题