做漫画网站的需求,安徽海鹏建设工程有限公司网站,永久免费个人网站注册,塘沽网站制作一。数据库打开 1.命令行 2.进入mysql mysql -uroot -p密码 3.退出 exit#xff1b; 二。针对数据库的操作
1.创建数据库#xff08;有分号#xff09;
create database student;
2.使用数据库
use student
3.删除数据库#xff08;有分号#xff09;
drop database…一。数据库打开 1.命令行 2.进入mysql mysql -uroot -p密码 3.退出 exit 二。针对数据库的操作
1.创建数据库有分号
create database student;
2.使用数据库
use student
3.删除数据库有分号
drop database student;
安全删除
drop database if exists student
4.查询数据有哪些表
注意必须先使用数据库才可以看数据库有哪些表
show tables
三。针对数据库中表的操作
1.创建表
1创建id为主键
create table student(
id int primary key,
name varchar(256),
sex varchar(2),
age int,
score int
);
2创建id为主键方法2
create table student(
id int,
name varchar(256),
sex varchar(2),
age int,
score int
primary key(id)
);
3创建多个主键并且id设为自增auto_increment
create table student(
id int auto_increment,
name varchar(256),
sex varchar(2),
age int,
score int
primary key(idname,age)
);
2.删除表
drop table student
3.表的重新命名
alter table student rename to student1;
4.表的字段类型展示
desc student; 5.插入数据
1插入单条数据
insert into student (id,name,sex,age,score)value(1,王五,男,25,60);
2插入多条数据
insert into student (id,name,sex,age,score)
values
(2,张三,男,27,75)
(3,李四,男,29,70);
三。表中数据类型数值类型日期、时间类型字符串类型
1.数值类型
1整数类型tinyint, smallint ,mediumint, int, bigint tinyint 很小的整形1个字节有符号-128-127 , 无符号0-255smallint 小的整形 2个字节有符号-32768-32767, 无符号0-65535mediumint 中等整形 3个字节有符号-8388608-8388607,无符号0-16777215int, 普通整形 4个字节bigint 大的整形 8个字节 设置成无符号字符
age tinyint unsigned,
2浮点数类型 浮点型和定点型 浮点型和定点型都可以使用(M,N的方式来表示) M精度总位数N:标度小数位数 float 单精度浮点型 4个字节 double 双精度浮点型 8个字节 decimal(M,N)定点型 M2字节 以串的方式存储 2.日期、时间类型 DATETIME类型 YYYY-MM-DD HH:MM:SS年月日 时分秒 1000-01-01 00:00:00 - 9999-12-31 23:59:59 8个字节范围 DATE YYYY-MM-DD 1000-01-01 - 9999-12-31 3个字节 TIMESTAMP YYYY-MM-DD HH:MM:SS 1970-01-01 00:00:00 - 2038-01-19 03:14:07 4个字节 TIME HH:MM:SS -838:59:59-838:59:59 3个字节 YEAR YYYY 1901-2155 1个字节 3.字符串类型 char(M) 固定长度字符串 M字节 1M255 varchar(M) 可变长字符串 L1字节LM, 1M255 (L字符串实际长度) text tinytext 小的字符串 L1字节L2^8 mediumtext 中等字符串 L2字节L2^16 longtext 长的文本 L3个字节L2^24 char和varchar区别: char是固定长度固定M个字节而varchar是实际长度1,实际长度不能超过M。 如果要求查询速度可以使用char, 尽量不要浪费空间。 varchar的查询速度低于char如果要求存储空间可以使用varchar。 四。查询数据表
1.全部查询
select * from student;
2.部分查询
select id,name from student;
3.条件查询两者等价
select * from student where sex!女;
select * from student where sex女;