Home > Database > Mysql Tutorial > mysql数据库中的primary key and key and index_MySQL

mysql数据库中的primary key and key and index_MySQL

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-01 13:35:03
Original
989 people have browsed it

bitsCN.com

mysql数据库中的primary key and key and index

 

mysql  数据库中有很多键,如外键(foregin,主键(primary key)之类。

 

[sql] 

  

而key,这个键,我感觉有点怪怪的,如下所示:

 

demo1:

 

[sql] 

create table test1(v_name varchar(20) key,age int );  

显示表的信息是:

 

mysql数据库中的primary key and key and index_MySQL

 

demo2:

 

[sql] 

create table test2(v_name varchar(20),age int ,key(v_name));  

显示表的信息是:

 

mysql数据库中的primary key and key and index_MySQL

 

key放在不同的位置,显示的信息却不一样。

 

我的理解是,test1中的key的位置的作用想当于主键(primary key)的作用,如v_name 不允许为空等等。

 

test2中的key的位置的作用相当于索引(index)的作用,如test2中没有要求v_name不允许为空的设置。

bitsCN.com
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template