mysql表和字段_mysql学习笔记1-表和字段的操作

创建表

在创建表之前要选择数据库,否则会暴错(No database selected),

这里有两种方法

1-create table db_name.table_name(利用点符号来引用)

2-在使用前先生命在哪个数据库创建 use db_name (例如在 test数据库里面就是 usetest)

创建表的语句:

Create table tb_name [结构] [选项]

Exp:

create table admin (

id  int,

name varchar(20),

pwd varchar(32)

) ;

表的命名规则:

表的命名规则和数据库命名规则类似。(他会在数据库的目录下创建一个文件,但是不是一定的。)

表的查询:

查看全部表 show tables;

查看包含关键词的表 show tables like ‘%xxx%’;

Exp: show tables like ‘%dd’ ;查询以dd结尾的表名

查看表的创建语句 :show create table tb_name ;

表的重命名rename table tb_name tonewname ; 可以支持一次性修改多个表;

Exp:rename teble xss to new_xss , inject to new_inject;

表的重命名还支持跨数据库,

Exp:rename teble xss to db.xss;//这样在当前数据库xss表会被删除,在db数据库会添加一个表

查看表结构describe tb_name ; (describe 可以简写为desc )

Exp: desc xss;

删除一个表:droptable [if exists] tb_name;

Exp:droptable  if esiste test; //加上if exists就算表不存在也不会报错。

修改表的字符属性altertable tb_name character set utf8; //把字符集修改为utf8编码

字段的命名规则:字段命名规则和表的类似;

字段信息的修改: alerttable tb_name [add|drop|change|modify];

1-添加一个字段:alert table tb_name add new_colum type

Exp: alert tablenima add ano int;

2-删除一个字段alter table tb_name drop colum

Exp: alter tablenima drop ano;

3-修改一个字段定义alter table tb_name modifycloum  type

Exp:alert tablenima modify item vharchar(33);

4-重命名一个列alter table tb_name changecloum new_colum type;

Exp: alter tablenima change id str_no varchar(30);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值