两列作为MySQL中具有自动递增功能的主键?
使用MyISAMEngine实现此目的。这是两列作为具有自动增量的主键的示例。
创建一个以两列为主键的表-
mysql> create table TwoPrimaryKeyTableDemo
-> (
-> Result ENUM('First','Second','Third','Fail') not null,
-> StudentId int not null auto_increment,
-> StudentName varchar(200) not null,
-> Primary key(Result,StudentId)
-> )
-> ENGINE=MyISAM;将记录插入表
mysql> insert into TwoPrimaryKeyTableDemo(StudentName,Result) values('John','Fail');
mysql> insert into TwoPrimaryKeyTableDemo(StudentName,Result)values('Carol','First');
mysql> insert into TwoPrimaryKeyTableDemo(StudentName,Result) values('Smith','Third');
mysql> insert into TwoPrimaryKeyTableDemo(StudentName,Result) values('Johnson','Second');
mysql> insert into TwoPrimaryKeyTableDemo(StudentName,Result) values('Johnson','Third');
mysql> insert into TwoPrimaryKeyTableDemo(StudentName,Result) values('Carol','Second');
mysql> insert into TwoPrimaryKeyTableDemo(StudentName,Result) values('Carol','Fail');现在,我们可以在带有orderby子句的select语句的帮助下检查记录。查询如下。
mysql> select *from TwoPrimaryKeyTableDemo order by StudentId,Result;
以下是输出-
+--------+-----------+-------------+ | Result | StudentId | StudentName | +--------+-----------+-------------+ | First | 1 | Carol | | Second | 1 | Johnson | | Third | 1 | Smith | | Fail | 1 | John | | Second | 2 | Carol | | Third | 2 | Johnson | | Fail | 2 | Carol | +--------+-----------+-------------+ 7 rows in set (0.00 sec)
热门推荐
10 医院探望朋友祝福语简短
11 毕业祝福语简短女朋友
12 春节虎年爸妈祝福语简短
13 儿童毕业祝福语 简短6
14 开工仪式横幅祝福语简短
15 孩子日常祝福语大全简短
16 清晨寄语诗句祝福语简短
17 结婚送亲认亲祝福语简短
18 虎年喝酒拜年祝福语简短