当前位置:网站首页>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
边栏推荐
- DirectExchange switch simple introduction demo
- Zotero | Zotero translator插件更新 | 解决百度学术文献无法获取问题
- Foreign trade website optimization - foreign trade website optimization tutorial - foreign trade website optimization software
- PCB抄板
- 第9章 异常try...except...else...finally
- R——避免使用 col=0
- 2022.07.14_每日一题
- 2022.07.13_每日一题
- DAY18: Xss Range Clearance Manual
- Run the NPM will pop up to ask "how are you going to open this file?"
猜你喜欢
随机推荐
2022.07.12_Daily Question
QFileInfo常规方法
金融租赁业务
解决win11/win10在登陆界面(解锁界面)点击获取每日壁纸无效的问题 - get Daily Lockscreen and Wallpaper - Win11/10的登录界面背景图片在哪里?
Conditional statements of shell (test, if, case)
Analysis of the principle and implementation of waterfall flow layout
Obtaining server and client information
codec2 BlockPool:unreadable libraries
Install the gstreamer development dependency library to the project sysroot directory
毫米波技术基础
LeetCode刷题——摆动序列#376#Medium
2022.07.13_每日一题
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
从入门到一位合格的爬虫师,这几点很重要
DirectExchange switch simple introduction demo
2022.07.20_每日一题
Gradle剔除依赖演示
电脑开机密码怎么设置?如何给你的电脑加上“安全锁”
Web浏览器工作流程解析
2022.07.22_每日一题



![[PSQL] SQL基础教程读书笔记(Chapter1-4)](/img/76/d416f79b7f2c93c1c79a285c30d3e6.png)





