美文网首页
第2章节_mysql基本使用作业

第2章节_mysql基本使用作业

作者: hello06 | 来源:发表于2021-01-30 22:15 被阅读0次

关卡一

使用命令行连接数据库服务器的命令是什么?

mysql -u用户名 -p密码

列出数据库的命令

​ * 查看所有数据库:show databases;

​ * 使用数据库:use 数据库名字;

​ * 查看当前使用的数据库:select database();

​ * 创建数据库:create database 数据库名字 charset= utf8;

​ * 删除数据库:drop database 数据库名字;

创建数据库python:create database python charset=utf8;

列出表的命令

​ * 查看当前数据库的所有表:show tables;

​ * 查看指定表的结构:desc 表名;

设计班级表结构为id、name、isdelete,编写创建表的语句:

create table classes (id int unsigned not null primary key auto_increment,

name varchar(20),

isdelete bit default 0

);

列出数据操作语句的语法

​ * 增加insert into 表名 values();

​ * 修改update table 表名 set

​ * 删除delete from 表名 where

​ * 基本查询select * from 表名;

向班级表中插入数据python1、python2、python3

insert into classes(name) values('python1'),('python2'),('python3');

关卡二

学生表结构设计为:姓名、生日、性别、家乡,并且学生表与班级表为多对一的关系,写出创建学生表的语句

create table students1 (id int unsigned not null primary key auto_increment,

name varchar(20),

birthday date,

gender enum('男','女'),

hometown varchar(20),

clsid int unsigned,

isdelet bit default 0

);

向学生表中插入数据:

​ * python1班有郭靖、黄蓉,要求:使用全列插入,一次一值

insert into students1 values(0,'郭靖','2009-01-01','男','内蒙古',1,0);

insert into students1 values(0,'黄蓉','2010-11-28','女','中原',1,0);

​ * python2班有杨过、小龙女,要求:使用指定列插入,一次一值

insert into students1(name,gender,clsid) values('杨过','男',2);

insert into students1(name,gender,clsid) values('小龙女','女',2);

​ * 未分班的学生有黄药师、洪七公、洪七婆,要求:使用指定列插入,一次多值

insert into students1(name) values('黄药师'),('洪七公'),('洪七婆');

查询学生的姓名、生日,如果没有生日则显示无

select name,ifnull(birthday,'无') from students1;

查询学生的姓名、年龄

select name,year(now())-year(birthday) as age from students1;

逻辑删除洪七婆

update students1 set isdelet=1 where name='洪七婆';

修改洪七公的性别为女

update students1 set gender='女' where name='洪七公';

关卡三

设计科目表subjects,包括科目名称

create table subjects(id int unsigned primary key not null auto_increment,

sname varchar(20),

isdelect bit default 0

);

向表中插入数据,科目名有:python、数据库、前端

insert into subjects values(0,'python',0),(0,'数据库',0),(0,'前端',0);

设计成绩表,字段包括:学生id、科目id、成绩

create table scores(id int unsigned not null primary key auto_increment,

sid int unsigned not null,

kid int unsigned not null,

score int unsigned not null

);

向成绩表中添加一些示例数据

insert into scores(sid,kid,score) values(1,1,90),(2,3,80),(3,2,70),(1,3,95);

相关文章

  • 第2章节_mysql基本使用作业

    关卡一 使用命令行连接数据库服务器的命令是什么? mysql -u用户名 -p密码 列出数据库的命令 ​ * 查看...

  • 《MySQL必知必会》学习笔记

    第1章 了解SQL第2章 MySQL简介第3章 使用MySQL一、 在你最初连接到MySQL时,没有任何数据库打开...

  • mysql

    mysql 数据库 使用系统:ubuntu 18.04 LTS 安装mysql 基本使用 登陆 : mysql ...

  • D2-mysql基本使用

    2.1 数据库操作 进入mysql 输入密码即可 查看Mysql版本(记得加括号) 查看当前时间(记得加括号) 查...

  • 5. Mysql基本使用(2)

  • MySQL基本使用

    函数 常用函数 数学函数 字符串函数 日期函数

  • mysql基本使用

    安装mysql 安装Yum Repositorywget https://dev.mysql.com/get/my...

  • MYSQL基本使用

    1.Win10下进入mysql数据库打开终端(快捷键:commd + R, 然后输入cmd回车)输入mysql -...

  • Mysql基本使用

    安装 Ubuntu安装 https://www.cnblogs.com/wuhou/archive/2008/09...

  • MySQL基本使用

    MySQL 是最流行的关系型数据库管理系统,在 WEB 应用方面 MySQL 是最好的 RDBMS(Relatio...

网友评论

      本文标题:第2章节_mysql基本使用作业

      本文链接:https://www.haomeiwen.com/subject/qjbjcktx.html