两列作为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 婆婆高寿祝福语大全简短