赞
踩
##数据库
SQL
insert into user values("刘德华",50);
如何连接数据库执行SQL语句
数据库中如何保存数据
SQL语句格式要求:
数据库相关SQL
数据库相关练习题:
1. 创建 mydb1和mydb2 数据库 字符集分别为utf8和gbk
create database mydb1 charset=utf8;
create database mydb2 charset=gbk;
show databases;
show create database mydb1;
show create database mydb2;
u
use mydb1;
drop database mydb1;
drop database mydb2;
表相关的SQL语句
use db1;
表相关练习题:
1. 创建数据库mydb3 字符集gbk 并使用
create database mydb3 charset=gbk;
use mydb3;
2. 创建t_hero英雄表, 有名字和年龄字段 默认字符集
create table t_hero(name varchar(20),age int);
3. 修改表名为hero
rename table t_hero to hero;
4. 查看表的字符集
show create table hero;
5. 查询表字段
desc hero;
6. 删除表
drop table hero;
7. 删除数据库
drop database mydb3;
表相关SQL(续)
use db1;
create table emp(name varchar(50));
表相关SQL语句回顾:
表相关练习题:
create database mydb4 charset=utf8;
use mydb4;
create table teacher(name varchar(50));
alter table teacher add age int;
alter table teacher add id int first;
alter table teacher add salary int after name;
alter table teacher drop age;
rename table teacher to t;
drop table t;
drop database mydb4;
数据相关SQL
create database mydb5 charset=utf8;
use mydb5;
create table person(name varchar(50),age int)charset=utf8;
insert into person values("Tom",18);
insert into person(name) values("Jerry");
insert into person values("lilei",28),("hanmeimei",28);
insert into person(name) values("aa"),("bb"),("cc");
insert into person values("刘德华",50);
如果执行上面SQL语句报如下错误
执行 set names gbk; 可以解决
数据相关SQL语句回顾
综合练习题 :
1. 创建数据库day1db 字符集utf8并使用
create database day1db charset=utf8;
use day1db;
2. 创建t_hero表, 有name字段 字符集utf8
create table t_hero(name varchar(20));
3. 修改表名为hero
rename table t_hero to hero;
4. 最后面添加价格字段money, 最前面添加id字段, name后面添加age字段
alter table hero add money int;
alter table hero add id int first;
alter table hero add age int after name;
5. 表中添加以下数据: 1,李白,50,6888 2,赵云,30,13888 3,刘备,25,6888
insert into hero values(1,'李白',50,6888),(2,'赵云',30,13888),(3,'刘备',25,6888);
6. 查询价格为6888的英雄名
select name from hero where money=6888;
7. 修改刘备年龄为52岁
update hero set age=52 where name='刘备';
8. 修改年龄小于等于50岁的价格为5000
update hero set money=5000 where age<=50;
9. 删除价格为5000的信息
delete from hero where money=5000;
10. 删除表, 删除数据库
drop table hero;
drop database day1db;
数据类型
整数: int(m) 和 bigint(m) , bigint等效java中的long, m代表显示长度,举例m=5,存18 查询到 00018 , 需要补零的话必须使用zerofill关键字
create table t1(age int(5) zerofill);
insert into t1 values(18);
select * from t1;
浮点数: double(m,d) m代表总长度,d代表小数长度 54.432 m=5 d=3
create table t2(price double(5,3));
insert into t2 values(45.2312312123);
insert into t2 values(455.231); //报错
字符串
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。