两列作为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 植物种植祝福语简短
14 翻译考试祝福语朋友简短
15 个人周年庆简短祝福语
16 狗狗怎么训练
17 分别祝福语简短搞笑英文
18 生日广州男生祝福语简短