当前位置:网站首页>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
边栏推荐
猜你喜欢
Yu Mr Series 】 【 2022 July 022 - Go Go teaching course of container in the dictionary
Obtaining server and client information
2022.07.12_每日一题
【解决】mysql本地计算机上的MySQL服务启动后停止。某些服务在未由其他服务或程序使用时将自动停止
PCB抄板
解决安装 Bun 之后出现 zsh compinit: insecure directories, run compaudit for list. Ignore insecure directorie
我开发了一个利用 Bun 执行 .ts / .js 文件的 VS Code 插件
One of the small practical projects - food alliance ordering system
【微服务】 微服务学习笔记二:Eureka注册中心的介绍及搭建
Run the NPM will pop up to ask "how are you going to open this file?"
随机推荐
多进程全局变量失效、变量共享问题
interrupt and pendSV
Log4net 思维导图
2022.07.14_每日一题
Chapter 17: go back to find the entrance to the specified traverse, "ma bu" or horse stance just look greedy, no back to search traversal, "ma bu" or horse stance just look recursive search NXM board
nohup原理
单点登录 思维导图
Obtaining server and client information
【Star项目】小帽飞机大战(八)
讲解实例+详细介绍@Resource与@Autowired注解的区别(全网最全)
tidyverse笔记——tidyr包
Financial leasing business
[PSQL] SQL基础教程读书笔记(Chapter1-4)
第十六章:构建n(5,7)阶素数幻方
04-SDRAM:读操作(突发)
Zero-Shot Learning & Domain-aware Visual Bias Eliminating for Generalized Zero-Shot Learning
Postgresql source code learning (33) - transaction log ⑨ - see the overall process of log writing from the insert record
Titanic 预测问题
codec2 BlockPool:不可读库
从 Google 离职,前Go 语言负责人跳槽小公司