Sql Bai1 Quan Li Ban Hang
create database bai10create table tcd(Matcd char(10) primary key,Tentcd nvarchar(30) not null)create table cd(Macdv char(10) primary key,Tencdv nvarchar(30) not null,NS datetime,NgayV datetime,Matcd char(10))create table kt(Macdv char(10) not null,Mskt char(10) not null,lido nvarchar(max),nam int,constraint khoachinh primary key (Macdv,Mskt),constraint MaM_khoangoai foreign key(Macdv)references cd(Macdv))create view v1asselect macdv,tencdv,NSfrom cdwhere Matcd in(select Matcd from tcd where tentcd=N'hệ thống thông tin') create view v2asselect macdv,tencdv,NSfrom cdwhere Macdv not in(select Macdv from kt)create view v3asselect macdv,tencdv,NSfrom cdwhere Macdv in(select Macdv from kt where lido=N'đề tài cấp bộ')create proc p1@Tentcd nvarchar(30)asselect *from cdwhere Matcd in (select Matcd from tcd where tentcd=@Tentcd)exec p1 N'hệ thống thông tin'create proc p2@Tentcd nvarchar(30),@nam intasselect *from cdwhere Matcd in (select Matcd from tcd where tentcd=@Tentcd) and macdv in(select Macdv from kt where nam=@nam)exec p2 N'hệ thống thông tin',2010create proc p3@Tentcd nvarchar(30)asdelete from cdwhere Matcd in (select Matcd from tcd where tentcd=@Tentcd)create trigger ktndlon ktfor insertasif (select Nam from inserted)<0beginprint N'dữ liệu nhập vào không hợp lệ'rollback tranendelse print N'dữ liệu nhập vào thành công'insert into ktvalues ('103','k4',N'đề tài cấp bộ',-3)declare nhap cursorfor select * from cd where Macdv not in (select Macdv from kt where nam=2010)declare @Macdv char(10),@Tencdv nvarchar(30),@NS datetime,@NgayV datetime,@Matcd char(10)open nhapprint cast(N'Mã CDV' as nchar(10))+cast(N'Tên CDV' as nchar(30))+cast(N'NS' as nchar(20))+cast(N'NgayV' as nchar(20))+cast(N'Mã TCD' as nchar(10))fetch next from nhapinto @Macdv,@Tencdv,@NS,@NgayV,@Matcd while @@fetch_status=0beginprint cast(@Macdv as nchar(10))+cast(@Tencdv as nchar(30))+cast(@NS as nchar(20))+cast(@NgayV as nchar(20))+cast(@Matcd as nchar(5))fetch next from nhapinto @Macdv,@Tencdv,@NS,@NgayV,@Matcdendclose nhap
Bạn đang đọc truyện trên: ZingTruyen.Xyz