Guest User

Untitled

a guest
Jun 18th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. create type keyword_list
  2. as table (
  3. keyword varchar(300)
  4. );
  5.  
  6. go
  7.  
  8. create table keyword (
  9. id int identity(1,1),
  10. keyword varchar(300) not null,
  11. language_id bigint not null,
  12. location_id bigint not null,
  13. last_updated date,
  14. constraint pk_keyword primary key nonclustered (id),
  15. constraint uc_keyword unique clustered (keyword, language_id, location_id)
  16. );
  17.  
  18. create table keyword_rank (
  19. id int identity(1,1) primary key,
  20. search_volume bigint not null,
  21. average_cpc bigint not null,
  22. created_at date not null,
  23. keyword_id int not null,
  24. constraint fk_keyword foreign key (keyword_id) references keyword(id)
  25. );
  26.  
  27. go
  28.  
  29. create or alter procedure create_keywords
  30. @list as keyword_list readonly,
  31. @language_id as bigint,
  32. @location_id as bigint
  33. as
  34. begin
  35. insert into keyword (keyword, language_id, location_id)
  36. select mk.keyword, @language_id, @location_id
  37. from (
  38. select distinct(mk.keyword)
  39. from @list mk
  40. where mk.keyword not in (
  41. select k.keyword
  42. from keyword k
  43. where k.language_id = @language_id
  44. and k.location_id = @location_id
  45. and k.keyword in (select l.keyword from @list l)
  46. )
  47. ) as mk
  48. end;
Add Comment
Please, Sign In to add comment