A MySQL 'create table' syntax example

 

I used to use MySQL every day for years, but over the last two years I haven't used it much. Today I needed to create a MySQL database table, and had to wonder for a few moments what the MySQLCREATE TABLE syntax was. Fortunately I have plenty of examples out here.

Here's a quick example of a MySQL "users" table:

drop table if exists users;

# TODO: verify that this constraint creates a true index for performance
create table users (
  id int auto_increment not null,
  username varchar(32) not null,
  password varchar(16) not null,
  primary key (id),
  constraint unique index idx_users_unique (username)
) ENGINE = InnoDB;

  

If you need more examples of the MySQL create table syntax, or examples of the MySQL unique constraint syntax, check out my MySQL Nagios database design. It includes many (many) database tables, and as a result, it covers examples of many MySQL features.

原文地址:https://www.cnblogs.com/hephec/p/4586864.html