SQL学习随笔-数据表操作

1.查看当前数据库的所有表

show tables;

2.创建表
create table 数据表名字 (字段 类型 约束[, 字段 类型 约束]);
auto_increment 表示自动增长
多个约束,不分先后顺序
设置主键,可以不写not null

-- 创建表 students
create table students(
	id int unsigned primary key auto_increment not null,
	name varchar(10) not null,
	age tinyint unsigned default 0,
	gender enum('男','女','中性','保密') default '保密',
	class_id int unsigned not null
	);

3.查看创建的表

show create table students;

4.查看表结构—使用频率相当高

desc students;

5.修改表结构—alter操作

  • 添加字段 alter table 表名 add 列名 类型/约束;
alter table students add birthday datetime default "2011-11-11 11:11:11";
  • 修改字段:不改变字段名,仅改变类型
alter table students modify birthday date default "2011-11-11";
  • 修改字段:改变字段名(alter table 表名 change 原列名 新列名 类型及约束;)
alter table students change birthday birth date default "2011-11-11";
  • 删除字段
alter table students drop birth;
  • 删除表xx
drop table xx;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值