prestige

13

May 17th, 2012
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 1.64 KB | None | 0 0
  1.  
  2. use master
  3. go
  4. if exists(select * from sys.databases where name ='dbmoe')
  5.     drop database dbmoe
  6. go
  7. create database dbmoe
  8. go
  9. use dbmoe
  10. go
  11. create table Encrip_ganr
  12. (
  13.  id int identity(1,1) PRimary key not null,
  14.  name_ganr nvarchar(20)
  15. )
  16. create table Encrip_film
  17. (
  18.  id int identity(1,1) PRimary key not null,
  19.  name_film nvarchar(20) not null,
  20.  dist int,
  21.  kod_ganr int not null,
  22.  anotaciya nvarchar(10),
  23.  foreign key (kod_ganr) references Encrip_ganr(id),
  24. )
  25. create table Encrip_chanel
  26. (
  27.  id int identity(1,1) PRimary key not null,
  28.  name_film nvarchar(20)
  29. )
  30. create table Main
  31. (
  32.  id int identity(1,1) PRimary key not null,
  33.  kod_film int not Null,
  34.  kod_chanel int not null,
  35.  time_begin real check (dbo.f1(time_begin)='true'),
  36.  time_end real,
  37.  foreign key (kod_film) references Encrip_film(id),
  38.  foreign key (kod_chanel) references Encrip_chanel(id),
  39.  check (dbo.f2(dist,Main.time_begin,Main.time_end)='true')
  40. )
  41. go
  42. create trigger Myinsert1
  43. on Main
  44. instead of insert
  45. as
  46.     declare @a int=0
  47.     if(exists(select kod_film from inserted))
  48.         set @a=@a+1
  49.     if(exists(select kod_chanel from inserted))
  50.         set @a=@a+1
  51.     if @a=2
  52.      insert into Main values(select * from inserted)
  53. go
  54. if OBJECT_ID('view1','view')
  55.     drop view view1
  56. go
  57. create view view1
  58. as
  59.     select Encrip_film.name_film,Encrip_film.anotaciya from Main inner join Encrip_film on Main.kod_film=Encrip_film.id
  60.     inner join Encrip_ganr on Encrip_film.kod_ganr=Encrip_ganr.id
  61.     inner join Encrip_chanel on Encrip_chanel.id=Main.kod_chanel
  62. go
  63. --if OBJECT_ID('view1','view')
  64. --  drop view view1
  65. --create procedure proc1
  66. --as
  67.   create procedure proc1 @kod_f int,@kod_c,@time_b
  68. go
Advertisement
Add Comment
Please, Sign In to add comment