当前位置:网站首页>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
边栏推荐
猜你喜欢
链表实现及任务调度
Obtaining server and client information
【面试:并发篇37:多线程:线程池】自定义线程池
那些破釜沉舟入局Web3.0的互联网精英都怎么样了?
【解决】npm ERR A complete log of this run can be found in npm ERR
【Go】Go 语言切片(Slice)
DAY18: Xss Range Clearance Manual
Automatic translation software - batch batch automatic translation software recommendation
手把手教你开发微信小程序自定义底部导航栏
2022.07.29_每日一题
随机推荐
HighTec 的安装与配置
【解决】npm ERR A complete log of this run can be found in npm ERR
Fund investment advisory business
解决win11/win10在登陆界面(解锁界面)点击获取每日壁纸无效的问题 - get Daily Lockscreen and Wallpaper - Win11/10的登录界面背景图片在哪里?
Introduction and self-order of bcos
bcos简介及自序
2022.07.15_每日一题
360 push-360 push tool-360 batch push tool
DAY18: XSS vulnerability
R——避免使用 col=0
【Star项目】小帽飞机大战(八)
深度学习通信领域相关经典论文、数据集整理分享
链表实现及任务调度
金融租赁业务
Chapter 16: Constructing the Magic Square for Prime Numbers of Order n(5,7)
Difficulty comparison between high concurrency and multithreading (easy to confuse)
线程唤醒机制
任务及任务切换
LeetCode brush # 376 # Medium - swing sequence
Gradle remove dependency demo