当前位置:网站首页>mysql的建表语句_三种常用的MySQL建表语句
mysql的建表语句_三种常用的MySQL建表语句
2022-07-31 06:21:00 【time Friend】
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'
);
完整例子:
DROP TABLE IF EXISTS `user_t`;
CREATE TABLE `user_t` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(40) NOT NULL,
`password` varchar(255) NOT NULL,
`age` int(4) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8;
/*Data for the table `user_t` */
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 字段。
————————————————
版权声明:本文为CSDN博主「朱昆 iamkun」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_33582089/article/details/113112792
边栏推荐
- postgresql源码学习(34)—— 事务日志⑩ - 全页写机制
- Zero-Shot Learning & Domain-aware Visual Bias Eliminating for Generalized Zero-Shot Learning
- 2022.07.18_每日一题
- 2022.07.12_Daily Question
- codec2 BlockPool:不可读库
- 04-SDRAM: Read Operation (Burst)
- 熟悉而陌生的新朋友——IAsyncDisposable
- 03-SDRAM: Write operation (burst)
- tidyverse笔记——dplyr包
- postgresql源码学习(33)—— 事务日志⑨ - 从insert记录看日志写入整体流程
猜你喜欢
Titanic 预测问题
Leetcode952. Calculate maximum component size by common factor
【第四章】详解Feign的实现原理
[PSQL] SQL基础教程读书笔记(Chapter1-4)
Postgresql source code learning (34) - transaction log ⑩ - full page write mechanism
Zotero | Zotero translator插件更新 | 解决百度学术文献无法获取问题
【 TA - frost Wolf _may - "one hundred plan" 】 art 2.3 hard surface
批量免费文字翻译
Automatic translation software - batch batch automatic translation software recommendation
2022.07.14_每日一题
随机推荐
DAY18:XSS 漏洞
知识、创新、回报。
van-uploader上传图片,使用base64回显无法预览的问题
[PSQL] 复杂查询
基金投顾业务
熟悉而陌生的新朋友——IAsyncDisposable
2022.07.12_Daily Question
剑指offer(一)
【Go语言入门教程】Go语言简介
金融租赁业务
03-SDRAM: Write operation (burst)
【微服务】Nacos集群搭建以及加载文件配置
interrupt and pendSV
04-SDRAM:读操作(突发)
Postgresql source code learning (34) - transaction log ⑩ - full page write mechanism
Yu Mr Series 】 【 2022 July 022 - Go Go teaching course of container in the dictionary
Analysis of the principle and implementation of waterfall flow layout
Foreign trade website optimization - foreign trade website optimization tutorial - foreign trade website optimization software
完美指南|如何使用 ODBC 进行无代理 Oracle 数据库监控?
Web浏览器工作流程解析