数据操纵语言
数据操纵语言包括增加、更新和删除
1.增加
数据类型要一致
一、单一记录增加查询
eg. insert into student values('05350001','齐心','女','#1988-01-01#','汉族','团员','信息学院','电商05-1','北京市','排球','');
二、多重记录增加查询
insert into ... select ... from...
2.更新
eg.对岗位津贴低于800元的教师,在其原有岗位津贴的基础上增加20%,重新计算岗位津贴。
update salary set 岗位津贴=岗位津贴*(1+0.2) where 岗位津贴<=800;
eg.给所有女教师的岗位津贴增加200元
update salary,teacher set 岗位津贴=岗位津贴+200
where teacher.教师编号=salary.教师编号 and 性别="女";
3.删除
eg.删除salary表中教师编号首位是’0‘的记录
delete from salary where 教师编号 like "0*";
数据定义语言
数据定义语言:创建表、限制、索引及关系
1.创建表
create
数据类型
二进制数据 binary 固定长度/变长度 varbinary n位固定二进制数据 image 以位字符串储存 字符串数据 char 定长字符数据,其长度最多8KB varchar 变长字符数据,长度不超8KB text 超过8KB 日期和时间数据类型 datetime 年月日 smalldatetime 年月日和时间 数字数据类型 int 正数和负数 smallint 小数(浮点型) tinyint 整数,0-225 货币数据类型 money 8个存储字符 smallmoney 4个存储字符 是否 yesno 数字 number
eg.用create命令建立mytable表,id字段为自动编号主键
create table mytable
(id couter primary key,mytext text(10));
eg.用create建立student表,学号为主键
create table student
(学号 text(8) primary key,姓名 text(10),性别 text(1),出生日期 datetime);
eg.用create命令建立grade表,其中“学号”和“课程编号”为双字段主键,并于student表建立联系
create table grade
(学号 text(8) references student (学号),课程编号 text(6),成绩 number,primary key(学号,课程编号));
2.删除表
eg.删除mytable表
drop table mytable
3.修改表
eg1.在mytable表中增加一个notes字段,类型为文本型,长度为25
alter table mytable add column notes text(25)
eg2.将mytable表中的zipcode字段的长度修改为10
alter table mytable alter column zipcode text(10)
eg3.删除mytable表中的notes字段
alter table mytable drop column notes