創建名字叫做mydb的數據庫:
create database mydb;
選擇數據庫名:
use mydb;
刪除數據庫:
drop database mydb;
查看數據庫:
show databases;
創建表:
create table student(
姓名 varchar(10),
性別 varchar(2) ,
出生日期 date,
收入 int(6));
查表:
show tables;
顯示表結構:
show columns mydb;
插入一行數據:
insert into student(姓名,性別) values('張三','男');
修改數據:
update student set 性別='女' where name='張三';
刪除記錄:
delete form student 刪除所有記錄;
delete from student where 姓名='張三';
清除數據:
truncate table student;
查詢:
select * from student;查詢全部
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 人數 from student;查詢總人數
select year(now())-year(出生日期) as 年齡 from student;
select zgxx.姓名,出生日期,工資,獎金 from gz,zgxx where gz.職工號=zgxx.職工號 and 性別='女';鏈接查詢