两列作为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 教师闺蜜祝福语简短