【数据库】1库、引擎、约束、表、字段、数据
来源:互联网 发布:linux qt调试器未设置 编辑:程序博客网 时间:2024/06/05 16:24
一、库
二、引擎
InnoDB:事务型数据库首选引擎,支持事务安全表,支持行锁定
MyISAM:较高的插入,查询速度,不支持事物
MEMORY:将表中数据存储到内存,默认
三、约束
create table 表名(
sno int ①primary key ⑧auto_increment,
sname varchar(10)⑤not null,
sage int(4)⑥unique,
ssex varchar(20) ⑦default ‘男’,(default 111)
②primary key(son),
③foreign key(sno)references 另一个表(id);
⑨check (sno>0)
);
②可以多字联合主键primary key(son,sname,sage)
四、表
1、创建 creat
create table 表名(
sno int primary key auto_increment,
sname varchar(10)not null,
sage int(4)unique,
ssex varchar(20) default ‘男’,(default 111)
primary key(son),
foreign key(sno)references 另一个表(id)
);
2、 删除表(先删子,再删父)
drop table 表名; drop table if exists 表名1,表名2
3、改表名
alter table 旧名 rename 新名;
4、查看表
show tables;desc 表名;show create tables 表名/G;
5、别名
select * from 表 as 别名 where 别名.字段=条件;
select c.c_id,o.o_id from cus as c left join order as o on c.c_id=o.o_id;
6、另存为表
create table 新名 as select * from 旧名;
五、字段
1、增
alter table 表名 add 列名 类型()not null;
alter table 表名 add 列名 类型() (first/after 已存在列名 );
2、 删除
alter table 表名 drop 字段名;
3、改列名
alter table 表 change 旧名 新名 数据类型(旧名=新名只改变数据类型)
改数据类型
alter table 表modify 列名 数据类型
改位置
alter table 表 modify 列名 数据类型 first/after 列名2;
4、查
desc 表名;
5、别名 as
select f1.f_name as fruit_name,f1.f_price as fruit_price from fruit as f1 where f1.fprice<8;
六、数据
1、增
insert into 表名(列名1,列名2) value (‘据1’,’据2’);
insert into 表名(列名1,列名2) value (‘据1’,’据2’),(‘据3’,’据4’);
没有写列名,插入数据必须与表中所有字段一致,主键插入为null
返回信息:
. Recorde插入记录条数
. Duplicutes插入被忽略记录(主键重复)
. Warning有问题数值(数据类型)
2、 删除
delete from 表 where 条件;自动增长,不会从1开始
清空:truncate table 表;自动增长从1开始
删除重复:delete distinct 类型 from 表名;
3、改 updatate set value
update 表 set 字段=值,字段=值 where 条件;
4、查询结果插入表中
insert into 表1(列名)select 列名 from 表2;
- 【数据库】1库、引擎、约束、表、字段、数据
- 数据库数据约束
- 数据库字段太长,做唯一性约束
- 数据库之约束和修改字段
- 数据库<1.1> 字段的约束及属性
- 数据库-数据存储引擎
- MYSQL数据库数据引擎
- 数据库字段数据截取
- ORACLE数据库的数据对象-表、约束、视图、索引、序列
- 约束字段
- 字段约束
- MySql数据库的基本操作-表数据中的 唯一约束 & 默认约束
- SqlServer2005数据库查找所有表和字段及其属性和约束的sql语句
- SqlServer2005数据库查找所有表和字段及其属性和约束的sql语句
- 数据库表的约束
- 数据库表的约束
- 数据库表的约束
- Oracle数据库表约束
- 显卡内存一直被占用解决方式
- Maven对重复依赖的解决方案
- HDU 1040 JAVA
- Maven profile介绍
- ATS 6.2.1打release版本rpm包时插件中出现undefined symbol的问题追踪
- 【数据库】1库、引擎、约束、表、字段、数据
- UML建模详解
- bindingSource具体使用案例
- 数组操作(2)-二维数组
- 一种判断文件存在的方法
- input中text和password文本框的常用参数
- 【学习路线】最新Java开发资料汇总(持续更新ing)
- LinkedIn是如何优化Kafka的
- Android 笔记