MYSQL基础笔记(二)-SQL基本操作

SQL基本操作

基本操作:CRUD,增删改查

  将SQL的基本操作根据操作对象进行分类:

  1、库操作

  2、表操作

  3、数据操作

库操作:

对数据库的增删改查

  新增数据库:

  基本语法:

 Create database 数据库名字[库选项];

  库选项:用来约束数据库,分为两个选项:1、字符集设定:charset/character set 具体字符集(数据存储的编码格式,中文常用字符集gbk和utf8.)。2、校对集设定:collate 具体校对集(数据比较的规则)。

  例如:

  aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAoAAAACXCAIAAAAK431+AAAQLUlEQVR4nO3cXZazthKFYeY/Kg/tXGR9PrRUtbVLCAz2+1xkGSFKpR8kdyedbQMAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAHf2er1er9ens/i/T+Wzqt27jSf+w/wCuKO7bSifyidsdyKZu40n/sP8Agi8Ile2fqtQtzqARXk1zoOc1IV7rvMvmN8bpgR+WfIY73nqP1zWdFM4sSstWXB3O33DW6Kn0/mf8bp+cB6z4NmHs5Xmdy7OR1z/PUa4TyZ3wGg8z30mbC6T++S/UPYd5YwmzjiDL3vqPvFLLkjmW8cz/G76gTyucrfercrnKb8EOr3d+0zwPTfuTzl7ozlv3O45j3dbJ0/v7302xLvN7Fp36x0H8LkNNL9fev31LumDHP/F1D5+ltXw9dN59vWnU80GKuvCRBNhyZJxzsZzSb+umceqLJM+MdGuyP9gPllic5H9+fWj9eW6aR2kH+phSlm/RJDj/Q3TFvnrfvX5mJWd/MUIiH5lHewvq/lkj4g4ulDfCiuH3RHjkFU2+zujD913ssm1qZPVn8gkDKvjh/lnzy4hEljYtO7XSfGzy1K/7jmP91nn4vFPza8TxJmv8FIHqU6x/16s6u/EexGWO+ttLm1dX4zPxDr386nG0Yt/Yr01H64Z/7KwgdLErMp4Lr4/MavoF/Kaho63VRq3Ulv3nMf7rPNhQ0scH09dYSJ+s9M5ORxpd1V/J94Lvdiay7Wv+fHxWZVPdf3sbw17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Y8MkywdbKIJP87EgVfN04kwnc/cehbxOYABHLL8ANatVHfJ8NlVG1/pAB4WZnnOHfO66bDcnK9VcZ5+AFfj+wEBwDJ3ADdENB1zLp9HHMDvkXFaEZVLB3A4LxMHsBPHHL1hj6pL4kg+2aKdGDezRQBINafFZmxwYt/Rt8wtMitpNs1hqIm2SjX1+Oz/6QcfHldLai6JMz16HzyAnThmQE5fAAvsd6LsMBA/GZjnonkAi4BObiUnHcCbsbmHD4YdmT6AnaELU3UOvNKYi1TNmKXczDSq6/ngeQ8Asdc/orw5g5tHXn+FTRzJp89EbI5+/OFBomtmt7LNXbey5YMcDkXY7jBV0brTrzBVp4NmoyKCmbyOsGTc/I4DgKu0q1YjnxH2guBY4mvm6Gs6AuD7nXeov+OfFxwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADzL/wDucPq7002l3wAAAABJRU5ErkJggg==" alt="" />

  其中:数据库名字不能用关键字(已经被使用的字符)或保留字。

  如果非要使用关键字或则保留字,那么必须使用反引号。(esc 下面的英文状态下输入`)。

当创建数据库的SQL语句执行之后,发生了什么?

  1、在数据库系统中,增加了对应的数据库信息

  2、会在保存数据的文件夹下:Data目录,创建一个对应数据库名字的文件夹。

  查看数据库

  1、查看所有数据库 

 show databases;

  2、查看指定部分的数据库:模糊查询

 show database like 'pattern';   

  --pattern是指匹配模式:%(百分号):表示匹配多个字符。_(下划线):表示匹配单个字符。

  3、查看数据库的创建语句

 show create database 数据库名字;

  更新数据库

  数据库名字是不可以修改的。

  数据库的修改仅限库选项:字符集和校对集(小堆积依赖字符集)。

 Alter database 数据库名字[库选项] chaerset XXX;

  删除数据库

 Dorp database 数据库名 ;

 上一节:MYSQL基础笔记(一)

下一节:MYSQL基础笔记(三)-表操作基础

上一篇:创建Activity


下一篇:前台报错:Uncaught TypeError: Cannot read property '0' of null