1.Mysql中表student_table(id,name,birth,sex),插入记录。
插入要求:
修改name字段为NULL的记录,是男生时设置name=‘男生姓名’,是女生时设置name=‘女生姓名’。
插入语句:
update student_table set name = ( case when sex = '男' then '男生姓名' when sex = '女' then '女生姓名' end) where name is null ;
2.数据库语言分类
1.select语句—>查询
2.数据操纵语言(DML语句)data manipulation language
insert, update, delete
3.数据定义语言(DDL语句)data definition language
create(创建), alter(修改), drop(删除), rename(重命名), truncate(删除表中的数据)
4.[事务]控制语句(TCL语句)transction control
commit(提交), rollback(回滚), savepoint(记录点,用来回滚)
5.数据控制语言(DCL语句)data control language
grant【授权】, revoke【回收】
3.已知职员表employee(eno,ename,gender,birthday,salary),现有一张E表,表结构与职员表一致,要求将E表中没有在职员表中出现的女职员添加到职员表中。
INSERT INTO employee(eno,ename,gender,birthday,salary)
SELECT eno,ename,gender,birthday,salsry
FROM E
WHERE E.gender='女' and NOT EXISTS(
SELECT * FROM employee
WHERE employee.eno=E.eno)
4.
在关系数据库中用关系模型来表示数据结构,表示为一个二维表,一个关系就是一个二维表。
5.某电器商品海关进口税征收办法,起征点为500元,超出部分按以下2级计算:
1 、超过0至150, 税率3% 。
2、 超过150元以上 ,税率10% 。
商品进口税=(商品总额-500)*税率
程序输出:编写一个函数,实现输入商品的总额,返回该商品的进口税。
CREATE FUNCTION goods
( @total AS money)
RETURNS money AS
BEGIN
declare @income money
declare @tax money
select @income=@total-500
if @income<=0 set @tax=0
else begin
if(0<@income and @income<=150)
select @tax=@income*0.03
if(@income>150)
select @tax=@income*0.1
end
return @tax
END