Home  >  Article  >  php教程  >  mysql 数据表中主键(primary key)的操作

mysql 数据表中主键(primary key)的操作

WBOY
WBOYOriginal
2016-06-07 17:23:571730browse

     总结了一下,mysql数据表中的主键(primary key)有如下几种约束
1、PRIMARY KEY 约束唯一标识数据库表中的每条记录。
2、主键必须包含唯一的值。
3、主键列不能包含 NULL 值。
4、每个表都应该有一个主键,并且每个表只能有一个主键。

在创建主键时,我们可以在创建表的同时创建主键,当然有时出于疏忽,建好表后才发现没有创建主键,这时可以补上。
下面是在MYSQL控制台创建主键的两种方法。


1、在创建表时一起创建主键,我们可以这样

mysql> CREATE TABLE `wb
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn