USE [sqlysimon508]
GO
/****** 对象: Table [dbo].[SiteData] 脚本日期: 12/13/2008 23:28:55 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SiteData](
[id] [int] IDENTITY(1,1) NOT NULL,
[site] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[riqi] [datetime] NULL,
[baidu] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NULL,
[google] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NULL,
[yahoo] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NULL,
[iask] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NULL,
[sogou] [nvarchar](50) COLLATE Chinese_PRC_CI_AS NULL,
[zhongsou] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NULL,
[alexa] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NULL,
[pr] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]
GO
/****** 对象: Table [dbo].[SiteList] 脚本日期: 12/13/2008 23:28:58 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[SiteList](
[ID] [uniqueidentifier] NOT NULL,
[site] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NOT NULL,
[title] [nvarchar](255) COLLATE Chinese_PRC_CI_AS NULL,
[showcount] [int] NULL CONSTRAINT [DF_SiteList_showcount] DEFAULT (1),
[lastUpdate] [datetime] NULL CONSTRAINT [DF_SiteList_lastUpdate] DEFAULT (getdate())
) ON [PRIMARY]
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE VIEW [dbo].[vSitelist]
AS
SELECT dbo.SiteList.ID, dbo.SiteList.site, dbo.SiteData.riqi, dbo.SiteData.baidu, dbo.SiteData.google, dbo.SiteData.yahoo, dbo.SiteData.iask,
dbo.SiteData.sogou, dbo.SiteData.zhongsou, dbo.SiteData.alexa, dbo.SiteData.pr
FROM dbo.SiteList LEFT OUTER JOIN
dbo.SiteData ON dbo.SiteData.site = dbo.SiteList.site
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Proc_AddSite]
@title varchar(200),
@site varchar(100),
@siteid varchar(36) ,
@baidu varchar(10),
@google varchar(10),
@yahoo varchar(10),
@iask varchar(10),
@sogou varchar(10),
@zhongsou varchar(10),
@pr varchar(10),
@alexa varchar(10)
AS
BEGIN
set @siteid=newid()
declare @scount int
set @scount=(select count(site) from sitelist where site=@site)
if @scount>0
begin
update [sitelist] set showcount=showcount+1,lastupdate=getdate() where site=@site
set @siteid=(select id from [sitelist] where site=@site)
end
else
begin
insert into [sitelist] ([id],showcount,lastupdate,title,site) values(@siteid,1,getdate(),@title,@site)
end
delete from sitedata where site=@site and riqi between convert(datetime,left(getdate(),10)+' 00:00:00.000') and convert(datetime,left(getdate(),10)+' 00:00:00.000')+1
insert into sitedata(site,riqi,baidu,google,yahoo,iask,sogou,zhongsou,pr,alexa) values (@site,getdate(),@baidu,@google,@yahoo,@iask,@sogou,@zhongsou,@pr,@alexa)
select @siteid as siteid;
END
GO
/****** 对象: StoredProcedure [dbo].[Proc_GetMyList] 脚本日期: 12/13/2008 23:38:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[Proc_GetMyList]
@sites varchar(400)
AS
BEGIN
--select a.*,sitelist.id as sid from sitedata a left join sitelist on a.site=sitelist.site where a.id in (
--select max(id) from sitedata where site in (select site from sitelist where id in ('fc8de2e0-1a24-401c-8fc3-696d71885a80','970f8e0c-6aaa-4f87-83d7-9df2ef0ab206')) group by site
--)
declare @sqlstr varchar(800)
set @sqlstr='select a.*,sitelist.id as sid from sitedata a left join sitelist on a.site=sitelist.site where a.id in (select max(id) from sitedata where site in (select site from sitelist where id in ('+@sites+')) group by site)'
--set @sqlstr='select * from sitedata where riqi between convert(datetime,left(getdate(),10)+'' 00:00:00.000'') and convert(datetime,left(getdate(),10)+'' 00:00:00.000'')+1 and site in (select site from sitelist where id in ('+@sites+'))'
print @sqlstr
exec (@sqlstr)
END
GO
/****** 对象: StoredProcedure [Proc_GetCurrentList] 脚本日期: 12/13/2008 23:38:14 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [Proc_GetCurrentList]
AS
BEGIN
select top 20 * from sitelist order by lastupdate desc
END