創(chuàng)建名字叫做mydb的數(shù)據(jù)庫:
create database mydb;
選擇數(shù)據(jù)庫名:
use mydb;
刪除數(shù)據(jù)庫:
drop database mydb;
查看數(shù)據(jù)庫:
show databases;
創(chuàng)建表:
create table student(
姓名 varchar(10),
性別 varchar(2) ,
出生日期 date,
收入 int(6))勉抓;
查表:
show tables攘须;
顯示表結(jié)構(gòu):
show columns mydb;
插入一行數(shù)據(jù):
insert into student(姓名,性別) values('張三','男')甸怕;
修改數(shù)據(jù):
update student set 性別='女' where name='張三';
刪除記錄:
delete form student 刪除所有記錄眼五;
delete from student where 姓名='張三'吏廉;
清除數(shù)據(jù):
truncate table student;
查詢:
select * from student;查詢?nèi)?br>
select 姓名 from student where 性別='男';按條件查詢需要字段
select 姓名 from student where 姓名 like '%張%';查詢名字帶張的人姓名
select 姓名 from student where 姓名 like '張__';查詢張某某的名字
select distinct 姓名 from student; 查詢名字不同的,相同的合并
select max(工資) as 最大,min(工資) as 最小,avg(工資) as 平均 from student;
select count(*) as 人數(shù) from student;查詢總?cè)藬?shù)
select year(now())-year(出生日期) as 年齡 from student;
select zgxx.姓名,出生日期,工資,獎(jiǎng)金 from gz,zgxx where gz.職工號(hào)=zgxx.職工號(hào) and 性別='女';鏈接查詢