赞
踩
一、创建:create
1.创建数据库
create database 库名;
2.创建表
create table 表名(
列名1 数据类型(size),
列名2 数据类型(size),
列名3 数据类型(size),
....
列名n 数据类型(size)
);
二、添加:inster
1.添加单个/多个数据
insert into 表名 value('*** ','***','***',);
2.同时添加多个数据
inster into 表名(列名1,列名2,......)
values('*** ','***','***',),
('*** ','***','***',),
('*** ','***','***',);
三、删除:drop,delete、truncate
1.删除库/表
drop database/table 库名/表名;
【扩展】
drop table 库名.表名;
2.删除表中的数据
delete from 表名 where 条件;
【扩展】
truncate table 表名;
delete from 表名;
四、实例
数据
学生表
课程表
成绩表
1.创建
#创建数据库 create database 学生管理系统; #在该数据库下创建表 alter database 学生管理系统 char set gbk; use 学生管理系统; create table Student( 学号 varchar(10) primary key, 姓名 varchar(50) not null, 性别 varchar(10) check (性别 in ('男','女')), 专业班级 varchar(10), 出生日期 varchar(10), 电话 varchar(20) ); create table Course( 课程号 varchar(10), 课程名 varchar(10), 学分数 int, 学时数 int, 任课教师 varchar(10) ); create table Tscore( 课程号 varchar(10), 学号 int, 成绩1 int, 成绩2 int, 成绩3 int );
2.添加
insert into Student value('0433','张艳','女','生物04','1986-9-13',NULL); insert into Student value('0496','李越','男','电子04','1984-2-23','138129xxxx'); insert into Student value('0529','赵欣','男','会计05','1984-1-27','1350222xxxx'); insert into Student value('0531','张志国','男','生物05','1986-9-10','1331256xxxx'); insert into Student value('0538','于兰兰','女','生物05','1984-2-20','1331200xxxx'); insert into Student value('0591','王丽丽','女','电子05','1984-3-20','1332080xxxx'); insert into Student value('0592','王海强','男','电子05','1986-11-1',NULL); insert into Course value('K001','计算机图形学','2.5','40','胡晶晶'); insert into Course value('K002','计算机应用基础','3','48','任泉'); insert into Course value('K006','数据结构','4','64','马跃先'); insert into Course value('M001','政治经济学','4','64','孔繁星'); insert into Course value('S001','高等数学','3','48','赵晓尘'); insert into Tscore value('K001','0433','60','75','75'); insert into Tscore value('K001','0529','70','70','60'); insert into Tscore value('K001','0531','70','80','80'); insert into Tscore value('K001','0591','80','90','90'); insert into Tscore value('K002','0496','80','80','90'); insert into Tscore value('K002','0529','70','70','85'); insert into Tscore value('K002','0531','80','80','80'); insert into Tscore value('K002','0538','65','75','85'); insert into Tscore value('K002','0592','75','85','85'); insert into Tscore value('K006','0531','80','80','90'); insert into Tscore value('K006','0591','80','80','80'); insert into Tscore value('M001','0496','70','70','80'); insert into Tscore value('M001','0591','65','75','75'); insert into Tscore value('S001','0531','80','80','80'); insert into Tscore value('S001','0538','60',NULL,'80');
3.删除
#删除数据库
drop database 学生管理系统;
#删除表
drop table Student;
#删除表中所有数据
delete from Student;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。