bitsCN.com
一、数据表
为了确保数据的完整性和一致性,在创建表时指定字段名称,字段类型和字段属性外,还需要使用约束(constraint),索引(index),主键(primary key)和外键(foregin key)等。
约束条件:
not null 非空约束
unique 唯一性约束
立即学习“PHP免费学习笔记(深入)”;
primary key 主键约束
foreign key 外键约束
check 检查约束
auto_increment 自动标识列(值会自动增1)
创建表:

修改表:
修改表的结构,如修改列的类型,添加新的字段,删除原有字段,更改表名称
alter%20table%20user%20modify/add/drop/change/rename
删除表:
添加数据(一次添加一条和一次添加多条)
查询:
修改表数据:
删除表中记录:
当表中字段很长时:书写不方便,我们可以使用as给字段起别名:

去掉查询中重复,使用distinct

查询数值在某一范围:select * from user where age between.. and ..

查询在给出值的集合中的值:select * from user where name in('"lixq", "lxq");

模糊查询:
%:代表0到多个字符
_:代表一个任意字符

二、索引
索引在数据库开发中,可以提高查询优化,确保数据的唯一性,以及可以对任何全文索引字段中大量文本的搜索进行优化,索引的分类:主键索引(primary key),唯一索引(unique),常规索引(index),全文索引(fulltext);

三、数据库表类型及存储位置
Mysql支持MYISAM,InnoDB,MEMORY等多种数据表类型

查看当前数据库支持存储引擎

一般在mysql的安装目录下的data文件中存储数据表
四、数据表的默认字符集
在mysql数据库中,可以为数据库,数据表,甚至每一个数据列分别设定一个不同的字符集,使用create table命令创建数据库时,若没有指定任何字符集,则是mysql配置文件里character-set-server选项决定的。

修改按照目录下的my.ini文件
<strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong><strong>default-character-set=utf8character-set-server=utf8</strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong></strong>
windows中显示中文会出现问题,加一个set names gbk 显示就会正常
bitsCN.com
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号