当前位置:网站首页>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
边栏推荐
- DAY18: XSS vulnerability
- 文件 - 02 上传文件:上传临时文件到服务器
- 解决安装 Bun 之后出现 zsh compinit: insecure directories, run compaudit for list. Ignore insecure directorie
- 金融租赁业务
- 庐山谣寄卢侍御虚舟
- opencv、pil和from torchvision.transforms的Resize, Compose, ToTensor, Normalize等差别
- Super detailed mysql database installation guide
- 【微服务】(十六)—— 分布式事务Seata
- 2022.07.20_Daily Question
- 电脑开机密码怎么设置?如何给你的电脑加上“安全锁”
猜你喜欢
DAY18:XSS 漏洞
2022.07.29_Daily Question
2022.07.14_Daily Question
那些破釜沉舟入局Web3.0的互联网精英都怎么样了?
文件 - 04 下载文件: 根据文件下载链接下载文件
2022.07.20_每日一题
Conditional statements of shell (test, if, case)
Postgresql source code learning (33) - transaction log ⑨ - see the overall process of log writing from the insert record
Embedded system driver primary [2] - _ parameters and dependencies under the kernel module
Foreign trade website optimization - foreign trade website optimization tutorial - foreign trade website optimization software
随机推荐
超级详细的mysql数据库安装指南
van-uploader uploads images, and cannot preview the image using base64 echo
‘vite‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
任务及任务切换
【Star项目】小帽飞机大战(八)
Thread 类的基本用法——一网打尽
测试 思维导图
关于求反三角函数的三角函数值
2022.07.20_每日一题
知识、创新、回报。
Kubernetes调度
2022.07.14_Daily Question
The Perfect Guide|How to use ODBC for Agentless Oracle Database Monitoring?
How to set the computer password?How to add "safety lock" to your computer
SCI写作指南
事务的传播机制
MySQL安装到最后一步 write configuration file 失败 怎么办?及后安装步骤
Leetcode952. Calculate maximum component size by common factor
熟悉而陌生的新朋友——IAsyncDisposable
Financial leasing business