只要使用innodb就要为表指定主键;

如果不指定mysql就会自己找不为空且为一的作为主键,如果找不到,就会使用默认的(软件自己预定好的)作为主键;

主键分为单列主键和复合主键,用法和单列唯一,联合唯一一样;

copy from oldboy egon;

# 单列主键
create table t17(
id int primary key,
name char(16)
);

create table t18(
id int not null unique,
name char(16)
);

# 复合主键
create table t19(
ip char(15),
port int,
primary key(ip,port)
);

primary key的更多相关文章

  1. ORA-02429: cannot drop index used for enforcement of unique /primary key

    相信不少人遇到过ORA-02429: cannot drop index used for enforcement of unique /primary key 这个错误,对应的中文提示"O ...

  2. SQL PRIMARY KEY 约束\SQL FOREIGN KEY 约束\SQL CHECK 约束

    SQL PRIMARY KEY 约束 PRIMARY KEY 约束唯一标识数据库表中的每条记录. 主键必须包含唯一的值. 主键列不能包含 NULL 值. 每个表都应该有一个主键,并且每个表只能有一个主 ...

  3. Hibernate Id Generator and Primary Key

    Use automate id by hibernate: If you want the tables' id be created automation. How to do it? When u ...

  4. Database Primary key and Foreign key [From Internet]

    Database Primary key and Foreign key --Create Referenced Table CREATE TABLE Department ( DeptID int ...

  5. SQLite主键自增需要设置为integer PRIMARY KEY

    按照正常的SQL语句,创建一个数据表,并设置主键是这样的语句: ), EventType )) 但使用这种办法,在SQLite中创建的的数据表,如果使用Insert语句插入记录,如下语句: INSER ...

  6. ASP.NET MVC another entity of the same type already has the same primary key value

    ASP.NET MVC项目 Repository层中,Update.Delete总是失败 another entity of the same type already has the same pr ...

  7. 1503 - A PRIMARY KEY must include all columns in the table's partitioning function

    1503 - A PRIMARY KEY must include all columns in the table's partitioning function 错误的原因:表的主键字段必须包含分 ...

  8. (转)Sqlite中INTEGER PRIMARY KEY AUTOINCREMENT和rowid的使用

    原文:http://www.cnblogs.com/peida/archive/2008/11/29/1343832.html Sqlite中INTEGER PRIMARY KEY AUTOINCRE ...

  9. mysql中key 、primary key 、unique key 与index区别

    一.key与primary key区别 CREATE TABLE wh_logrecord ( logrecord_id ) NOT NULL auto_increment, ) default NU ...

  10. Primary key and Unique index

    SQL> create table t1(id1 char(2),id2 char(2),id3 char(2)); Table created. SQL> desc t1 Name Nu ...

随机推荐

  1. 初学 Babel 工作原理

    前言 Babel 对于前端开发者来说应该是很熟悉了,日常开发中基本上是离不开它的. 已经 9102 了,我们已经能够熟练地使用 es2015+ 的语法.但是对于浏览器来说,可能和它们还不够熟悉,我们得 ...

  2. Typescript进阶之路

    TypeScript 何为TypeScript 一.编程语言类型 动态类型语言(Dynamically Typed Language) 类型的检查是在运行时才做 例子---JavaScript.Rub ...

  3. Java(25-40)【数据类型转换、运算符、方法入门】

    1.ASCII编码表 0--48 A--65 a--97 2. Unicode万国码 字符'中'为20013 3.算数运算符 double类型的加上int类型结果为double byte short ...

  4. Unity2D项目-平台、解谜、战斗! 1.5 Player框架、技能管理组件

    各位看官老爷们,这里是RuaiRuai工作室,一个做单机游戏的兴趣作坊. 前文提到,凡是有"攻击"语义的对象,在游戏中,我们给予其一个"CanFight"组件予 ...

  5. kube-batch 创建的pod 一直是Pending

    官网的例子 apiVersion: batch/v1 kind: Job metadata: name: qj-1 spec: backoffLimit: 6 completions: 6 paral ...

  6. 如何查看spark版本

    使用spark-shell命令进入shell模式

  7. .Net之静态资源

    介绍 静态文件都存储在Core Web根目录中.默认目录是<content_root>/wwwroot,但可通过 UseWebRoot方法更改访问目录.而content_root是指web ...

  8. goloader - golang动态加载的实现

    github地址:https://github.com/dearplain/goloader 这里有以前的一些思路:http://www.cnblogs.com/dearplain/p/8145985 ...

  9. Tomcat部署环境

    环境搭建:程序文件(开发人员),相关的软件(web服务器,应用服务器,数据服务器),硬件(服务器设备上),网络环境. 文档:部署文档说明书(操作系统,硬件配置,服务器软件及相关..) 下面举个列子,考 ...

  10. 14- 小程序测试与airtest自动化测试

    什么是小程序 小程序是一种不需要下载安装即可使用的应用,它实现了应用"触手可及"的梦想,用户扫一扫或者搜一下即可打开应用.也体现了"用完即走"的理念,用户不用关 ...