当前位置: 代码迷 >> SQL >> sql server ,sql语句,练习题笔记
  详细解决方案

sql server ,sql语句,练习题笔记

热度:120   发布时间:2016-05-05 09:46:14.0
sql server ,sql语句,练习笔记

一、删除冗余记录

DELETE [学生表] WHERE id NOT IN (SELECT MIN(id) FROM [学生表] GROUP BY [学号],[姓名],[课程编号],[课程],[分数])

 

二、创建触发器

if (object_id('账户插入', 'tr') is not null)
drop trigger 账户插入
go
create trigger 账户插入
on [学生表]
for insert --插入触发
as
--定义变量
declare @id int, @name varchar(20), @temp int;
--在inserted表中查询已经插入记录信息
select @id = 分数, @name = 姓名 from inserted;
insert into [账户] values(@name, @id);
print '添加学生成功!';
go

删除字段

alter table [学生表] drop column id ;

增加字段
alter table [学生表] add id int NOT NULL identity(1,1);

  相关解决方案