当前位置:网站首页>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
边栏推荐
猜你喜欢
解决安装 Bun 之后出现 zsh compinit: insecure directories, run compaudit for list. Ignore insecure directorie
Run the NPM will pop up to ask "how are you going to open this file?"
基于交替迭代法的交直流混合系统潮流计算matlab程序iEEE9节点系统算例
解决win11/win10在登陆界面(解锁界面)点击获取每日壁纸无效的问题 - get Daily Lockscreen and Wallpaper - Win11/10的登录界面背景图片在哪里?
DirectExchange交换机简单入门demo
完美指南|如何使用 ODBC 进行无代理 Oracle 数据库监控?
自动翻译软件-批量批量自动翻译软件推荐
360推送-360推送工具-360批量推送工具
Obtaining server and client information
电脑开机密码怎么设置?如何给你的电脑加上“安全锁”
随机推荐
2022.07.24_每日一题
Redux state management
【Go语言入门教程】Go语言简介
2022.07.12_每日一题
Explain the example + detail the difference between @Resource and @Autowired annotations (the most complete in the entire network)
Bulk free text translation
Financial leasing business
‘vite‘ 不是内部或外部命令,也不是可运行的程序 或批处理文件。
2022.07.22_每日一题
2022.07.13_每日一题
leetcode 406. Queue Reconstruction by Height 根据身高重建队列(中等)
2022.07.12_Daily Question
04-SDRAM: Read Operation (Burst)
测试 思维导图
Jobject 使用
2022.07.14_每日一题
线程唤醒机制
单点登录 思维导图
多进程全局变量失效、变量共享问题
【Go】Go 语言切片(Slice)