create database testdb character set utf8;
use testdb;
select database();
create database testdb2 character set latin1;
use testdb2;
show create database testdb2;
drop database testdb;
drop database testdb2;
2、练习
1、创建库python1
2、在python1库中创建表 pymysql并指定字符集为utf8,字段有三个:id 、name char(15) 、 age
3、查看创建表pymysql的语句
4、查看pymysql的表结构
5、删除表pymysql
6、创建库python2
7、在python2中创建表t1并指定字符集为utf8,字段有 id 、name 、score,数据类型自己定义
8、查看t1的表结构
9、删除表t1
10、删除库 python2
答案:
[SQL] 纯文本查看复制代码
create database python1;
use python1;
create table pymysql(
id int,
name char(15),
age int
) character set utf8;
show create table pymysql;
desc pymysql;
drop table pymysql;
create database python2;
use python2;
create table t1(
id int,
name char(15),
score float(5,2)
) character set utf8;
desc t1;
drop table t1;
drop database python2;
show databases;
create database studb;
use studb;
create table tab1(
id int,
name char(10),
age int
)character set utf8;
desc tab1;
insert into tab1 values
(1,"张三丰",100),(2,"张无忌",30);
insert into tab1(name,age) values
("金毛狮王",88),("紫衫龙王",87);
select * from tab1;
select name,age from tab1;
select * from tab1 where age>20;
3、练习
1、创建库 studb2 ,并在库中创建表 stuinfo,要求:
id :大整型
name :字符类型,宽度为15
age :微小整型,不能为负数
height :浮点型,小数位为2位(float)
money :浮点型,小数位为2位(decimal)
2、查看stuinfo的表结构
3、查看stuinfo的默认字符集
4、在表中插入1条完整记录
5、查询所有表记录
6、在表中id 、name两个字段插入2条记录
7、查询所有学生的id和姓名
答案:
[SQL] 纯文本查看复制代码
create table stuinfo(
id int,
name char(15),
age tinyint unsigned,
height float(5,2),
money decimal(20,2)
);
desc stuinfo;
insert into stuinfo values (1,"Bob",23,176,88888.88);
select * from stuinfo;
insert into stuinfo(id,name) values
(2,"Jim"),(3,"Tom");
select id,name from stuinfo;
create database school;
use school;
create table students(
id int,
name char(15),
age tinyint unsigned,
gender char(2),
score float(5,2)
);
desc students;
insert into students values
(1,"张三",20,"男",95.56),
(2,"李四",21,"男",98.30),
(3,"王浅",21,"女",100);
insert into students (name,score) values
("tom",60),
("lili",56),
("zhao",58.56);
select name,score from sutdents;
select name,score from students where score>=60;