Advertisement
Guest User

Untitled

a guest
Dec 18th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. if OBJECT_ID(N'writers', N'U') is not null
  2. drop table writers
  3. go
  4. create table writers (
  5. wid int not null,
  6. firstname varchar(35) not null,
  7. midname varchar(35) null,
  8. lastname varchar(35) not null,
  9. tmp int
  10.  
  11. PRIMARY KEY (wid)
  12. );
  13. go
  14.  
  15. insert writers values
  16. (1, 'john', 'r.r.', 'tolkien', 1),
  17. (2, 'george', 'r.r.', 'martin', 2),
  18. (3, 'herbert', 'g.', 'wells', 3),
  19. (4, 'george', '', 'orwell', 4),
  20. (5, 'raymond', 'd.', 'bradbury', 5);
  21. go
  22.  
  23. select * from writers;
  24.  
  25.  
  26. --=====from lab7
  27. --if OBJECT_ID(N'bookshelf_ix_view', N'V') is not null
  28. -- drop view bookshelf_ix_view;
  29. --go
  30. --=====
  31. if OBJECT_ID(N'books', N'U') is not null
  32. drop table books
  33. go
  34. create table books (
  35. bid int IDENTITY(1, 1) not null,
  36. name varchar(254) not null,
  37. bwid int not null
  38. CONSTRAINT DF_books_bwid DEFAULT (3),
  39. year int null,
  40.  
  41. PRIMARY KEY (bid),
  42. CONSTRAINT FK_books_bwid
  43. FOREIGN KEY (bwid)
  44. REFERENCES writers(wid)
  45. ON DELETE SET DEFAULT
  46. );
  47. go
  48.  
  49. insert into books(name, bwid, year)
  50. values
  51. ('the lord of the rings', 1, 1954),
  52. ('the hobbit, or there and back again', 1, 1937),
  53. ('a song of ice and fire', 2, 1996),
  54. ('1984', 4, 1949),
  55. ('fahrenheit 451', 5, 1953);
  56. go
  57.  
  58. select * from books;
  59.  
  60.  
  61. /*
  62. NO ACTION -> Error
  63. SET DEAFULT -> set VALID deafult
  64. SET NULL -> -||- (CARE OF "NOT_NULL" value in books.bwid)
  65. CASCADE (del) -> -||-
  66. */
  67.  
  68. --delete from writers where writers.tmp = 1;
  69. --go
  70.  
  71. select * from writers;
  72. select * from books;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement