mySQL简单操作(一)

推荐学习网站(https://sqlzoo.net/wiki/SQL_Tutorial)

1、创建mSQL数据表(表名,表字段名,定义表字段)

create table tbl_name [if not exists] (...)

2、删除

  • drop table tbl_name :删除表(包括结构与内容)
  • delete from tbl_name [where clause]:删除表内内容(当safe mode关闭时,可以无条件语句)
  • truncate table tbl_name:删除表内全部内容,仅仅保留表结构

开启binlog前提下,可以恢复delete删除内容

3、插入

insert into tbl_name (col1, col2, ......, coln)

values

(value11, value12, ......, value1n), ......, (valuen1, valuen2, ......, valuenn)

  • 若为字符串型,values -'values'
  • 若同时插入所有列,可以不指定(col1, col2, ......, coln)

4、查询

select col1, ......, coln from tbl_name

[where clause]

[limit n]

[offset m]

5、修改(更新)内容

update tbl_name set col1=new_col1, col2=new_col2

[where clause]

批量修改function:col = replace(col, 'old', 'new')

6、修改表名,表字段

  • alter table tbl_name drop col1
  • alter table tbl_name add i int [first / after col2]

修改字段类型以及名称:modify / change

  • alter table tbl_name modify col1 char(10)
  • alter table tbl_name change col1 new_co1 char(10)

猜你喜欢

转载自www.cnblogs.com/hsiaz/p/10665856.html