MySQL建表语句是最基础的SQL语句之一,下面就为您介绍最常用的三种MySQL建表语句,如果您对MySQL建表语句方面感兴趣的话,不妨一看。

1、最简单的:

CREATE TABLE t1(
    id int not null,
    name char(20)
);
2、带主键的:

CREATE TABLE t1(
    id int not null primary key,
    name char(20)
);
b:复合主键
CREATE TABLE t1(
    id int not null,
    name char(20),
    primary key (id,name)
);
3、带默认值的:

CREATE TABLE t1(
    id int not null default 0 primary key,
    name char(20) default '1'
);

完整例子:

  1. DROP TABLE IF EXISTS `user_t`;
  2. CREATE TABLE `user_t` (
  3. `id` int(11) NOT NULL AUTO_INCREMENT,
  4. `user_name` varchar(40) NOT NULL,
  5. `password` varchar(255) NOT NULL,
  6. `age` int(4) NOT NULL,
  7. PRIMARY KEY (`id`)
  8. ) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
  9. /*Data for the table `user_t` */
  10. insert  into `user_t`(`id`,`user_name`,`password`,`age`) values (1,'测试','sfasgfaf',24);
讲解::
ENGINE=InnoDB使用innodb存储引擎
DEFAULT CHARSET=utf8 数据库默认编码为utf-8
AUTO_INCREMENT=1 自增键的起始序号为1
扩展:
1.InnoDB,是MySQL的数据库引擎之一,为MySQL AB发布binary的标准之一,InnoDB支持事务处理和外键等高级功能。
2.AUTO_INCREMENT会在新记录插入表中时生成一个唯一的数字。希望在每次插入新记录时,自动地创建主键字段的值,可以在表中创建一个 auto-increment 字段。

三种常用的MySQL建表语句的更多相关文章

  1. 基于表的数据字典构造MySQL建表语句

    表的数据字典格式如下: 如果手动写MySQL建表语句,确认麻烦,还不能保证书写一定正确. 写了个Perl脚本,可快速构造MySQL脚本语句. 脚本如下: #!/usr/bin/perl use str ...

  2. MySQL 建表语句 create table 中的列定义

    MySQL 建表语句 create table 中的列定义: column_definition: data_type [NOT NULL | NULL] [DEFAULT default_value ...

  3. 根据javabean转换为mysql建表语句与mapper内容

    原文地址:  https://www.cnblogs.com/Jeffscnblog/p/10072483.html 一般上,我们会使用数据库表转换为javabean.dao.或是mapper,就叫逆 ...

  4. 脚本工具---自动解析mysql建表语句,生成sqlalchemy表对象声明

    常规建表语句: CREATE TABLE `test_table` ( `id` int(11) NOT NULL, `name` char(64) NOT NULL, `password` char ...

  5. mysql 建表语句

    修改id为自动增长: alter table book b_ISBN int(11) auto_increment;   自动增长要加的:auto_increment 基本的sql语句: 选择:sel ...

  6. Mysql建表语句

    create table messages( id int unsigned primary key auto_increment, sender varchar(64) not null, gett ...

  7. mysql建表语句key的含义

    CREATE TABLE `admin_role` (  `adminSet_id` varchar(32) NOT NULL,  `roleSet_id` varchar(32) NOT NULL, ...

  8. 一则 Mysql 建表语句

    DROP TABLE IF EXISTS `nuvue`; CREATE TABLE `nuvue`( `id` ) UNSIGNED NOT NULL AUTO_INCREMENT, `status ...

  9. 三种常用的MySQL建表语句(转)

    MySQL建表语句是最基础的SQL语句之一,下面就为您介绍最常用的三种MySQL建表语句,如果您对MySQL建表语句方面感兴趣的话,不妨一看. 1.最简单的: CREATE TABLE t1(    ...

随机推荐

  1. Error:(13, 60) java: 程序包com.sun.tools.internal.xjc.reader.xmlschema.bindinfo不存在

    我在import maven项目时,pom.xml报错Missing artifact com.sun:tools:jar:1.5.0,经过盘查发现是pom引入的struts2相关jar包导致报错. ...

  2. org.codehaus.jackson.map.JsonMappingException: Can not construct instance of java.util.Date from String value '2012-12-12 12:01:01': not a valid representation (error: Can not parse date "2012-12-

    Jackson对于date的反序列化只支持几种,如果不符合默认格式则会报一下错误 org.codehaus.jackson.map.JsonMappingException: Can not cons ...

  3. 从零开始学C++之模板(三):缺省模板参数(借助标准模板容器实现Stack模板)、成员模板、关键字typename

    一.缺省模板参数 回顾前面的文章,都是自己管理stack的内存,无论是链栈还是数组栈,能否借助标准模板容器管理呢?答案是肯定的,只需要多传一个模板参数即可,而且模板参数还可以是缺省的,如下: temp ...

  4. Libnids(Library Network Intrusion Detection System) .

    Libnids(Library Network Intrusion Detection System)是一个网络入侵检测开发的专业编程接口.它实现了基于网络的入侵检测系统的基本框架,并提供了一些基本的 ...

  5. Create an Android library

    官方文档 创建 Android 库 [Create an Android library] Android 库在结构上与 Android app module 相同.它可以提供构建应用所需的一切内容, ...

  6. 【cocos2dx中Node类getParent和getChildByTag()】学习体会

    參考http://cn.cocos2d-x.org/doc/cocos2d-x-3.0/d3/d82/classcocos2d_1_1_node.html 当中和child.parent有关的成员函数 ...

  7. 斯坦福大学CS224d课程目录

    https://www.zybuluo.com/hanxiaoyang/note/404582 Lecture 1:自然语言入门与次嵌入 1.1 Intro to NLP and Deep Learn ...

  8. Total Commander如何设置自定义快捷键在当前目录打开ConEmu

    Total Commander,简称TC,原名Windows Commander,是Windows平台下功能最强大的全能文件管理器. 自从使用了TC基本上就很少再打开Window的文件夹了,因为TC不 ...

  9. XenServer修改DNS

    XenServer没法直接修改DNS,感觉好奇怪啊 修改方法: 1.进入命令行:  2.执行命令:      # xe pif-list 列出网卡的UUID.  3.执行命令:      # xe p ...

  10. [Spring Boot] Singleton and Prototype

    When we use Bean to do autowired, it actually use singleton, so even we create multi instanses, they ...