- 创建和删除数据库
- create database if not exists sql_store2; //创建
- drop database if exists sql_store2; //删除
-
-- 创建数据库 create database if not exists sql_store2; drop database if exists sql_store2;
- 创建表
- create table customers (someting);
-
-- 创建表 create table customers (customer_id int primary key auto_increment,first_name varchar(50) not null,points int not null default 0,email varchar(255) not null unique ); drop table if exists cumstomers;
- 更改表
- alter table customers (something);
- 注意,不要在生产环境下更改表,这样会造成非常严重的后果,只在测试数据库上尝试更改,确保它们执行正常,确保它们不会产生任何不良影响后,再在生产数据库中执行它们。
-
-- 更改表 alter table customers add last_name varchar(50) not null after first_name, add city varchar(50) not null, modify first_name varchar(255) default '', drop points;
- 创建关系
- 不同表之间的关系(主键,外键)
-
--创建关系 drop table if exists orders; create table orders(order_id int primary key auto_increment,customer_id int not null,order_date date not null,status tinyint not null, -- 完成所有列的设置foreign key fk_orders_customers (customer_id) -- 设置外键(列)references customers(customer_id) -- 引入外键的表on update cascade -- 外键约束on delete no action );
- 更改主键/外键
- 创建或删除 不同表之间的关系
- 字符集和排序规则
- 字符集:MySQL会把使用字符集将每个字符转换为它的数值表示,因此字符集是将每个字符映射到数字的表。
- 排序规则:每个字符集有默认的排序规则,决定了某类语言的字符是如何排序的
- 更改字符集方法
-
-- 更改字符集方法 create database db_name -- 创建数据库时character set latin1;alter database db_name -- 创建数据库后character set latin1;create table table1( -- 创建表时name varchar(50) character set latin1 not null -- 指定字符集 )character set latin1; alter table table1 -- 修改表时character set latin1;
- 存储引擎
- MySQL的存储引擎,决定了数据如何被存储,以及哪些功能可供我们使用
SQL - 创建 表和数据库
2025/11/12 14:43:13
来源:https://blog.csdn.net/m0_74403543/article/details/141321149
浏览:
次
关键词:SQL - 创建 表和数据库
版权声明:
本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。
我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com
热文排行
最新新闻
- 【Android】Android开发应用如何开启任务栏消息通知
- arduino R4 WIFI读取时间并在LED矩阵上显示
- Pytorch使用教学5-视图view与reshape的区别
- 山东大学软件学院项目实训-创新实训-基于大模型的旅游平台(三十)- 微服务(10)
- 编程-设计模式 6:适配器模式
- ORB-SLAM2 ----- LocalMapping::KeyFrameCulling()
- WHAT - React useEffect 依赖的 Object.is
- ④(上网管理行为-ACG)主备/主主
- Doris 数据库深度解析:架构、原理与实战应用
- 电力行业中分布式能源管理(Distributed Energy Management System, DEMS)的实现
推荐新闻
- 【Android】Android开发应用如何开启任务栏消息通知
- arduino R4 WIFI读取时间并在LED矩阵上显示
- Pytorch使用教学5-视图view与reshape的区别
- 山东大学软件学院项目实训-创新实训-基于大模型的旅游平台(三十)- 微服务(10)
- 编程-设计模式 6:适配器模式
- ORB-SLAM2 ----- LocalMapping::KeyFrameCulling()
- WHAT - React useEffect 依赖的 Object.is
- ④(上网管理行为-ACG)主备/主主
- Doris 数据库深度解析:架构、原理与实战应用
- 电力行业中分布式能源管理(Distributed Energy Management System, DEMS)的实现
