当前位置:网站首页>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
边栏推荐
- leetcode 406. Queue Reconstruction by Height 根据身高重建队列(中等)
- 2022.07.13_每日一题
- Yu Mr Series 】 【 2022 July 022 - Go Go teaching course of container in the dictionary
- LeetCode brush # 376 # Medium - swing sequence
- 【第四章】详解Feign的实现原理
- tidyverse笔记——管道函数
- 2022.07.12_Daily Question
- 批量翻译软件免费【2022最新版】
- 批量免费文字翻译
- Core Tower Electronics won the championship in the Wuhu Division of the 11th China Innovation and Entrepreneurship Competition
猜你喜欢

服务器和客户端信息的获取

【面试:并发篇38:多线程:线程池】ThreadPoolExecutor类的基本概念

2022.07.18_每日一题

360 push-360 push tool-360 batch push tool

解决安装 Bun 之后出现 zsh compinit: insecure directories, run compaudit for list. Ignore insecure directorie

Core Tower Electronics won the championship in the Wuhu Division of the 11th China Innovation and Entrepreneurship Competition

DAY18:Xss 靶场通关手册

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

PCB抄板
解决win11/win10在登陆界面(解锁界面)点击获取每日壁纸无效的问题 - get Daily Lockscreen and Wallpaper - Win11/10的登录界面背景图片在哪里?
随机推荐
2022.07.29_每日一题
leetcode 406. Queue Reconstruction by Height
从 Google 离职,前Go 语言负责人跳槽小公司
【Go】Go 语言切片(Slice)
DAY18:XSS 漏洞
2022.07.18_每日一题
04-SDRAM: Read Operation (Burst)
【Star项目】小帽飞机大战(七)
线程中断方法
One of the small practical projects - food alliance ordering system
电压源的电路分析知识分享
leetcode 406. Queue Reconstruction by Height 根据身高重建队列(中等)
Run the NPM will pop up to ask "how are you going to open this file?"
中断及pendSV
Bulk free text translation
【并发编程】ReentrantLock的lock()方法源码分析
文件 - 03 下载文件:根据文件id获取下载链接
【微服务】 微服务学习笔记二:Eureka注册中心的介绍及搭建
深度学习通信领域相关经典论文、数据集整理分享
【科普向】5G核心网架构和关键技术