zoukankan      html  css  js  c++  java
  • 新闻表存贮过程

    USE [newssystem]
    GO
    /****** Object:  StoredProcedure [dbo].[news_delete]    Script Date: 2013/12/10 22:18:29 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:  张良伟
    -- Create date: 2013-12-10 19:30
    -- Description: 删除新闻
    -- =============================================
    ALTER PROCEDURE [dbo].[news_delete]
    @id int
    AS
    BEGIN
    --先删除该新闻下的评论
    delete comment where newsId=@id
    --再删除新闻本身
    delete news where id=@id
    END

    USE [newssystem]
    GO
    /****** Object:  StoredProcedure [dbo].[news_selectByCaId]    Script Date: 2013/12/10 22:18:57 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

    -- =============================================
    -- Author:  张良伟
    -- Create date: 2013-12-10 19:30 
    -- Description: 根据类别ID取出该类别下的所有新闻
    -- =============================================
    ALTER PROCEDURE [dbo].[news_selectByCaId]
    @caid int 
    AS
    BEGIN
        select  n.id,n.title,n.createTime,c.[name] from news n
     inner join category c on n.caId=c.id and n.caId=@caid
     order by n.createtime desc
    END

    USE [newssystem]
    GO
    /****** Object:  StoredProcedure [dbo].[news_selectByCaId]    Script Date: 2013/12/10 22:19:21 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO

    -- =============================================
    -- Author:  张良伟
    -- Create date: 2013-12-10 19:30 
    -- Description: 根据类别ID取出该类别下的所有新闻
    -- =============================================
    ALTER PROCEDURE [dbo].[news_selectByCaId]
    @caid int 
    AS
    BEGIN
        select  n.id,n.title,n.createTime,c.[name] from news n
     inner join category c on n.caId=c.id and n.caId=@caid
     order by n.createtime desc
    END

    USE [newssystem]
    GO
    /****** Object:  StoredProcedure [dbo].[news_selectByContent]    Script Date: 2013/12/10 22:19:37 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:  张良伟 
    -- Create date: 2013-12-10 7:00
    -- Description: 根据内容搜素新闻
    -- =============================================
    ALTER PROCEDURE  [dbo].[news_selectByContent]
    @content varchar(1000)
    AS
    BEGIN
     select top 10 n.id,n.title,n.createTime,c.[name] from news n
     inner join category c on n.caId=c.id
     where n.content like'%'+@content+'%'
     order by n.createtime desc
    END

    USE [newssystem]
    GO
    /****** Object:  StoredProcedure [dbo].[news_selectById]    Script Date: 2013/12/10 22:19:51 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:  张良伟
    -- Create date: 2013-12-10 19:30 
    -- Description: 根据类别ID取出该条新闻主体内容
    -- =============================================
    ALTER PROCEDURE [dbo].[news_selectById]
    @id int
    AS
    BEGIN
    select title,[content],createTime,caId from news where id=@id
    END

    USE [newssystem]
    GO
    /****** Object:  StoredProcedure [dbo].[news_selectByTitie]    Script Date: 2013/12/10 22:20:07 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:  张良伟
    -- Create date: 2013-12-10 19:30 
    -- Description: 根据标题搜索新闻
    -- =============================================
    ALTER PROCEDURE [dbo].[news_selectByTitie]
    @title varchar(100)
    AS
    BEGIN
     select top 10 n.id,n.title,n.createTime,c.[name] from news n
     inner join category c on n.caId=c.id
     where n.title like '%'+title+'%'
     order by n.createtime desc
    END

    USE [newssystem]
    GO
    /****** Object:  StoredProcedure [dbo].[news_selectHotNews]    Script Date: 2013/12/10 22:20:23 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:  张良伟
    -- Create date:2013-12-10 19;00
    -- Description: 取出10条热点新闻(评论回复最多的十条新闻)
    --=============================================
    ALTER PROCEDURE [dbo].[news_selectHotNews]

    AS
    BEGIN
        select top 10 n.id,n.title,n.createTime,c.[name] from news n
        inner join category c on n.caId=c.id
     inner join comment com on com.newsId=n.id
        group by n.id,n.title,n.createTime,c.[name]
        order by n.createTime desc
    END

    USE [newssystem]
    GO
    /****** Object:  StoredProcedure [dbo].[news_selectNewNews]    Script Date: 2013/12/10 22:20:32 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:  张良伟 
    -- Create date: 2013-12-10 7:00
    -- Description: 选择最新十条新闻
    -- =============================================
    ALTER PROCEDURE [dbo].[news_selectNewNews]
    AS
    BEGIN
     select top 10 n.id,n.title,n.createTime,c.[name] from news n
     inner join category c on n.caId=c.id
     order by n.createtime desc

    END

    USE [newssystem]
    GO
    /****** Object:  StoredProcedure [dbo].[news_update]    Script Date: 2013/12/10 22:20:54 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:  张良伟
    -- Create date: 2013-12-10 19:30
    -- Description: 修改新闻
    -- =============================================
    ALTER PROCEDURE [dbo].[news_update]
    @id int,
    @title varchar(100),
    @content text,
    @caid int
    AS
    BEGIN
    UPDATE news
    set title=@title,[content]=@content,caId=@caid
    where id=@id
    END

  • 相关阅读:
    mysql GROUP_CONCAT 查询某个字段(查询结果默认逗号拼接)
    mysql中find_in_set的使用
    Libev源码分析07:Linux下的eventfd简介
    Libev源码分析06:异步信号同步化--sigwait、sigwaitinfo、sigtimedwait和signalfd
    Nova中的Hook机制
    Python深入:stevedore简介
    Libev源码分析05:Libev中的绝对时间定时器
    Python深入:setuptools简介
    Libev源码分析04:Libev中的相对时间定时器
    Libev源码分析02:Libev中的IO监视器
  • 原文地址:https://www.cnblogs.com/liangwei/p/3468335.html
Copyright © 2011-2022 走看看