继续浏览精彩内容
慕课网APP
程序员的梦工厂
打开
继续
感谢您的支持,我会继续努力的
赞赏金额会直接到老师账户
将二维码发送给自己后长按识别
微信支付
支付宝支付

mysql

杨华钟
关注TA
已关注
手记 1
粉丝 0
获赞 0

mysql
1、创建数据库(create database 数据库名)
2、查看数据库的有多少个 表用SHOW DATABASES
3、删除数据库(DROP DATABASE)
4、创建数据表CREATE TABLE 数据表(

)
5、查看数据表 show tables
6、desc student 查看表的基本信息
7、 show create table student 查看建表的语句
8、drop table student 删除表,不是删除表中数据,删除表中数据是用delete from student where
9、插入数据 INSERT into student VALUES()
10、DECIMAL可以有效防止浮点数丢失精度
11、text是不确定长度的字符串。
12、添加字段 alter table 表名
add 列名1 数据类型[约束][comment 注释],
add 列名2 数据类型[约束][comment 注释]
ALTER TABLE student
add address VARCHAR(200) not NULL,
add home_tel CHAR(11) not null

修改字段类型:
ALTER TABLE student
MODIFY home_tel VARCHAR(20) not null
修改字段名:
ALTER TABLE student CHANGE address home_address VARCHAR(200) not NULL
删除字段名:
ALTER TABLE student DROP home_address,
DROP home_tel

创建索引
create table 表名(
index (字段名)
)
添加索引
create index 索引名称 on 表名(字段)
show index from 表名
drop index 索引名称 on 表名

例如:
CREATE TABLE temp(
id int UNSIGNED PRIMARY key,
num DECIMAL(20,10));
drop database tb_teacher;
CREATE TABLE tb_teacher(
id int unsigned primary key auto_increment,
name varchar(20),
tel char(11) not null unique ,
married boolean not null default false
);
create table tb_dept(
deptno int unsigned primary key ,
dname varchar(20) not null unique ,
tel char(4) unique
);
create table tb_emp(
empno int unsigned primary key ,
ename varchar(20)not null ,
sex enum(“boy”,“girl”) not null ,
deptno int unsigned not null ,
hiredate date not null ,
foreign key tb_emp(deptno) references tb_dept(deptno)

);
create table tb_message(
id int unsigned primary key,
content varchar(200) not null,
type enum(‘note’) not null,
create_time timestamp not null,
index idx_type(type)
);
drop index idx_type on tb_message;
create index idx_type on tb_message(type);
show index from tb_message

打开App,阅读手记
0人推荐
发表评论
随时随地看视频慕课网APP