mysql 6.2使用_2. MYSQL基本使用(2)
1.學(xué)生表結(jié)構(gòu)設(shè)計(jì)為:姓名、生日、性別、家鄉(xiāng),并且學(xué)生表與班級(jí)表為多對(duì)一的關(guān)系,寫出創(chuàng)建學(xué)生表的語句
create table student
(name
birth
gender
hometown)
這里認(rèn)為 gender 默認(rèn)值1是表示男生,isdelete 默認(rèn)值0表示未刪除
create table students(
id int unsigned auto_increment primary key not null,
name varchar(10) not null,
birthday date,
gender bit default 1,
hometown varchar(20),
clsid int unsigned,
isdelete bit default 0
);
2. 向?qū)W生表中插入數(shù)據(jù):
? * python1班有郭靖、黃蓉,要求:使用全列插入,一次一值
? * python2班有楊過、小龍女,要求:使用指定列插入,一次一值
? * 未分班的學(xué)生有黃藥師、洪七公、洪七婆,要求:使用指定列插入,一次多值
insert into students values(0,'郭靖','2016-1-1',1,'蒙古',1,0);
insert into students values(0,'黃蓉','2016-5-8',0,'桃花島',1,0);
insert into students(name,gender,clsid) values('楊過',1,2);
insert into students(name,clsid) values('小龍女',2);
insert into students(name) values('黃藥師'),('洪七公'),('洪七婆');
3. 查詢學(xué)生的姓名、生日,如果沒有生日則顯示無
select name,ifnull(birthday,'無') from students;
4. 查詢學(xué)生的姓名、年齡
select name,year(now()) - year(birthday) as age from students;
5. 邏輯刪除洪七婆
update students set isdelete=1 where name='洪七婆'
6. 修改洪七公的性別為男
update students set gender=0 where name='洪七公'
總結(jié)
以上是生活随笔為你收集整理的mysql 6.2使用_2. MYSQL基本使用(2)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: winform利用委托传值到datagr
- 下一篇: mysql ef 随机排序_EFCore