MySQL automatic primary key

Updated on technology 2024-04-10
6 answers
  1. Anonymous users2024-02-07

    Test environment: winxp+sql server2000:

    primary key means that this table is the primary key. If you only want to add columns automatically, you can leave this statement unnecessary.

    create table #aa(id int identity(1,1) primary key,name char(20))

    insert into #aa(name)values('aa')

    insert into #aa(name)values('bb')

    insert into #aa(name)values('cc')

    select * from #aa

  2. Anonymous users2024-02-06

    If your table already exists, e.g. test table, create table test (name char(20));

    Now you need to add an auto-incrementing id, alter table test add id int primary key auto increment; That's it, and the id value will be incremented at the same time.

  3. Anonymous users2024-02-05

    Here's how it works:

    1. Create a table.

    create table t5

    id int auto_increment,name varchar(20) primary key,key(id));

    The name field is the primary key, and the id field is an auto-incrementing field.

    2. Try to insert data:

    insert into t5 (name) values ('a');

    Execution result: It can be seen that for the first time, the id field is 1.

    3. Insert the second data:

    insert into t5 (name) values ('b');

    Result: The second insertion is 2, so that the self-increment is achieved.

  4. Anonymous users2024-02-04

    Just set that field to the key, MySQL allows you to add autoincrement to the key, but only one column can be autoincremented. You add a key (index) to the original table as described below, and then you can auto-increment on the column you want.

    alter table add index name ( column );

  5. Anonymous users2024-02-03

    However, only one column can be self-incrementing. You add a key to the original table as follows the following statement.

  6. Anonymous users2024-02-02

    MySQL can only have one autogrow field per table, and this autogrow field can be used as a primary key or as a non-primary key, but please note that when you use an autogrow field as a non-primary key, you must add a unique index to it, otherwise the system will report an error. For example:

    1.Set the autogrow field as the primary key.

    create table t1 (id int auto_increment primary key,sid int);

    2.Set the autogrow field to a non-primary key, noting that the unique key must be added explicitly.

    create table t2 (sid int primary key,id int auto_increment unique);

    3.If you set the autogrow field to a non-primary key, an error will be reported if you do not add a unique index, as shown below.

    create table t3 (sid int primary key,id int auto_increment)。

    MySQL is a relational database management system developed by MySQL AB in Sweden and is now part of Oracle. MySQL is one of the most popular relational database management systems, and when it comes to web applications, MySQL is the best RDBMS (Relational Database Management System) application.

    MySQL is a relational database management system that keeps data in different tables instead of putting all the data in one large warehouse, which increases speed and flexibility.

    The SQL language used by MySQL is the most commonly used standardized language used to access databases. MySQL software adopts a dual licensing policy, divided into community version and commercial version, due to its small size, fast speed, low total cost of ownership, especially the characteristics of open source, generally small and medium-sized developers choose MySQL as the database.

    Due to the excellent performance of the Community Edition, it makes for a good development environment with PHP and Apache.

Related questions
6 answers2024-04-10

You need to write a stored procedure that can do the above functionality! After all, what you're describing has a branching structure!

5 answers2024-04-10

It seems that there is something called triggers in the DB, and there seems to be another thing called transactions.

9 answers2024-04-10

Left Links There are links Full Links Left Join, Right Join, Join

16 answers2024-04-10

The 3 integers of only 200w are definitely no problem, and they don't hit without tens of millions of influences. >>>More

5 answers2024-04-10

Foreign key. It must be the primary key of another table. >>>More