当前位置:网站首页>MySQL table creation statement_Three commonly used MySQL table creation statements
MySQL table creation statement_Three commonly used MySQL table creation statements
2022-07-31 07:46:00 【time Friend】
The MySQL table creation statement is one of the most basic SQL statements. Here are the three most commonly used MySQL table creation statements. If you are interested in MySQL table creation statements, you may wish to take a look.
1. The simplest:
CREATE TABLE t1(
id int not null,
name char(20)
);
2. With primary key:
CREATE TABLE t1(
id int not null primary key,
name char(20)
);
b: Composite primary key
CREATE TABLE t1(
id int not null,
name char(20),
primary key (id,name)
);
3. With default value:
CREATE TABLE t1(
id int not null default 0 primary key,
name char(20) default '1'
);
Complete example:
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,'test','sfasgfaf',24);
Explanation::
ENGINE=InnoDB uses the innodb storage engine
DEFAULT CHARSET=utf8 The default encoding of the database is utf-8
AUTO_INCREMENT=1 The starting sequence number of the auto-increment key is 1
Extension:
1. InnoDB is one of MySQL's database engines, and one of the standards for the release of binary for MySQL AB. InnoDB supports advanced functions such as transaction processing and foreign keys.
2.AUTO_INCREMENT generates a unique number when a new record is inserted into the table.If you want to automatically create the value of the primary key field every time a new record is inserted, you can create an auto-increment field in the table.
—————————————————
Copyright statement: This article is an original article by CSDN blogger "Zhu Kun iamkun", following the CC 4.0 BY-SA copyright agreement, please reprintA link to the original source and this statement are attached.
Original link: https://blog.csdn.net/weixin_33582089/article/details/113112792
边栏推荐
猜你喜欢
解决win11/win10在登陆界面(解锁界面)点击获取每日壁纸无效的问题 - get Daily Lockscreen and Wallpaper - Win11/10的登录界面背景图片在哪里?

基金投顾业务

iOS大厂面试查漏补缺

把 VS Code 当游戏机

【面试:并发篇37:多线程:线程池】自定义线程池

双倍数据速率同步动态随机存储器(Double Data Rate Synchronous Dynamic Random Access Memory, DDR SDRAM)- 逻辑描述部分

从 Google 离职,前Go 语言负责人跳槽小公司

Zabbix6.2惊喜发布!特别优化中大型环境部署的性能!

Thread 类的基本用法——一网打尽

‘vite‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
随机推荐
2022.07.14_Daily Question
事务的传播机制
2022.07.20_Daily Question
【Go语言入门】一文搞懂Go语言的最新依赖管理:go mod的使用
[PSQL] 复杂查询
Kubernetes调度
解决安装 Bun 之后出现 zsh compinit: insecure directories, run compaudit for list. Ignore insecure directorie
opencv、pil和from torchvision.transforms的Resize, Compose, ToTensor, Normalize等差别
Postgresql source code learning (33) - transaction log ⑨ - see the overall process of log writing from the insert record
Tasks and task switching
文件 - 07 删除文件: 根据fileIds批量删除文件及文件信息
【Go语言入门教程】Go语言简介
Embedded system driver primary [2] - _ parameters and dependencies under the kernel module
2022.07.15_每日一题
【微服务】Nacos集群搭建以及加载文件配置
基金投顾业务
van-uploader上传图片,使用base64回显无法预览的问题
手把手教你开发微信小程序自定义底部导航栏
DAY18: XSS vulnerability
【Star项目】小帽飞机大战(八)