-- mysql基本语句
-- 创建数据库
create database data;
-- 打开数据库 创建数据表
use data
create table student (
id int not null,
name varchar(11) not null,
age tinyint(10)
) charset uft8 ;--设置表的字符集;
第二种方法;
create table data.teacher(
id int not null,
name varchar(11) not null,
age tinyint(10),
salary int (5000) not null,
)charset uft8 ;--设置表的字符集;
-- 查看数据库 中的表个数
show tables;
-- 查看表创建结构
show create tables;
-- 查看错误警告
show warning;
-- 表的结构操作增加字段
alter table student_id int(10) not null;
-- 删除表中的字段
alter table drop student_id;
--修改表中的字段类型和属性
alter table modify salary deciaml(6,2) not null;
--修改字段名字
alter table student id change student_id int(10) not null;
--修改表名字
alter table student rename to xueshengbiao ;
-- 插入表的值
insert inot student (id,name,age)values(1,'mysql',20);
-- 插入方法二
insert inot student values(1,'mysql',20);
-- 清除表中的数据
delete from student;
-- 清除表中某条记录的值
delete from student where id=1;
-- 查询表结构
desc student;
-
高级部分
-- 创建索引
create table student (
id int not null auto_increment priamry key,
name varchar(11) not null,
age tinyint(10)
) charset uft8 ;
-- 联合主键
create table student (
id int not null,
name varchar(11) not null,
age tinyint(10),
primary key(id,name);
) charset uft8 ;
-- 主键不能被修改,只能删除后,在增加
alter table student drop primary key id;
-- 增加主键
alter table add primary key (id,name);
-- 唯一索引
create table student (
id int not null unique key ,-- 唯一建自动增加为主键索引
name varchar(11) not null,
age tinyint(10)
) charset uft8 ;
-- 删除唯一索引
alter table student drop index(id);
-- 增加唯一索引
alter table student add index id;
-- 未完待续---