-- =============================================
-- Create database template
-- =============================================
USE master
GO

-- Drop the database if it already exists
IF  EXISTS (
	SELECT name 
		FROM sys.databases 
		WHERE name = N'skive'
)
DROP DATABASE skive
GO

CREATE DATABASE skive
GO

--create tables
USE skive
GO

IF OBJECT_ID('feeds', 'U') IS NOT NULL
  DROP TABLE feeds
GO

CREATE TABLE feeds
(
feed_uri varchar(255),
title varchar(250) not null,
updated datetime
)
GO

IF OBJECT_ID('entries', 'U') IS NOT NULL
  DROP TABLE entries
GO

CREATE TABLE entries
(
feed_uri varchar(255) not null,
title varchar(250),
updated datetime,
content xml
)
GO

IF OBJECT_ID('getAllURIs', 'U') IS NOT NULL
  DROP procedure getAllURIs
GO

create procedure getAllURIs
													
as
begin

select feed_uri,title,updated from feeds

end

IF OBJECT_ID('SaveURI', 'U') IS NOT NULL
  DROP procedure SaveURI
GO

create procedure SaveURI @uri varchar(255),
							@title varchar(255),
							@updated datetime
as
begin
Insert into feeds(feed_uri,title,updated)
values(@uri, @title, @updated);
end

IF OBJECT_ID('DeleteURI', 'U') IS NOT NULL
  DROP procedure DeleteURI
GO

create procedure DeleteURI @uri varchar(255)
as
begin
delete from feeds where feeds.feed_uri = @uri;
end

--IF OBJECT_ID('updateURI', 'U') IS NOT NULL
--  DROP procedure updateURI
--GO

--create procedure updateURI @uri varchar(255)
--as
--begin
--update feeds 
--set
--where feeds.feed_uri = @uri;
--end

