• 新闻视频 15讲 编写(新闻表)剩下的存储过程 关于TODO 注释的作用


    今天把关于新闻表的存储过程写完

    //TODO: 文字

    这个是用来做什么用的呢?

    当我们在使用 PDF 阅读器的时候,当我们看到一半,不小心关闭的时候,下次再打开,还是会回到上次看到的地方,能记住你上次阅读的位置。能自动定位到你上次的地方。VS里面的 TODO 注释  也是起到一个书签的作用,当我们做了某些工作,而要过几天后再做的时候,那么我们做一个TODO标签,下次打开VS的时候,我们就可以查看一下之前已经定义好的TODO标记。也是起到一个记忆的作用,我们现在打开VS

    image

    image

    当我们双击下面的  标题的时候  会自动  跳到代码

    一个项目中,至少1个月,那么你做到哪里,你不一定会很记得。这个时候如果用一个TODO  就会显示你还有什么任务,而且还可以定位到代码。

    继续。写完剩下的存储过程。对照着 数据库关系表来写

    image

    group by 要在 order by 的下面

    而且  order by 里面 没有的,要放在 group by里面(这是我自己理解的)

    image

    image image

    image

    image image

    下面是本节讲到的 存储过程

    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    -- =============================================
    -- Author:		<李鹏>
    -- Create date: <2011-10-17 12:00>
    -- Description:	<取出最新条新闻(所属分类、新闻标题、发布时间)>
    -- =============================================
    --CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName> 
    CREATE PROCEDURE news_SelectNewNews
    
    AS
    BEGIN
    		select top 10  a.id,content,createtime,name
    		from news a, category b
    		where a.caId=b.id
    		order by createtime desc
    end		
    GO
    
    exec proNewsSelectNewNews
    
    
    -- =============================================
    -- Author:		<李鹏>
    -- Create date: <2011-10-18 11:45>
    -- Description:	<取出10条热点新闻(评论回复数最多的条新闻)>
    -- =============================================
    --CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName> 
    create proc news_SelectHotNews
    as
    begin
    		select a.id,a.title,a.createtime,  c.name,  COUNT(b.id) as comCount
    		from news a,comment b,category c
    		where a.id=b.newsid and a.caId=c.id
    		group by a.id,a.title,a.createtime,  c.name
    		order by comCount desc
    		 
    end
    
    exec news_SelectHotNews
    
    -- =============================================
    -- Author:		<李鹏>
    -- Create date: <2011-10-19 16:50>
    -- Description:	<根据类别ID取出该类别下的所有新闻>
    create proc news_SelectByCaID
    @caid int
    as
    begin
    	select a.id,a.title,a.createtime,a.content,b.name
    	from news a, category b
    	where a.caId=b.id and a.caId=@caid
    	order by a.createtime desc
    end
    
    --exec news_SelectBycaid 9
    
    -- =============================================
    -- Author:		<李鹏>
    -- Create date: <2011-10-19 16:54>
    -- Description:	<根据新闻ID取出该条新闻主体内容>
    create proc news_SelectByNewsID
    @newsid int
    as
    begin
    	select title,[content] ,createtime ,caId  
    	from news
    	where id=@newsid
    end
    
    --exec news_SelectByNewsID 3
    
    -- =============================================
    -- Author:		<李鹏>
    -- Create date: <2011-10-19 16:57>
    -- Description:	<根据标题搜索新闻>
    alter proc news_searchByTitle
    @title varchar(50)
    as
    begin 
    	select top 10  a.id,a.title,content,createtime,name
    		from news a, category b
    		where a.caId=b.id and a.title like '%'+@title+'%'
    		order by createtime desc
    end
    
    --exec news_searchByTitle '标'
    
    -- =============================================
    -- Author:		<李鹏>
    -- Create date: <2011-10-19 17:43>
    -- Description:	<根据内容搜索新闻>
    create proc news_searchByContent
    @content varchar(200)
    as
    begin 
    	select top 10  a.id,a.title,content,createtime,name
    		from news a, category b
    		where a.caId=b.id and a.content like '%'+@content+'%'
    		order by createtime desc
    end
    
    exec news_searchByContent ''
    
    -- =============================================
    -- Author:		<李鹏>
    -- Create date: <2011-10-19 17:45>
    -- Description:	< 增加新闻>
    create proc news_Insert
    @title varchar(200),@content text,@caid int
    as
    begin
    
    INSERT INTO news(title, [content], caId)
    VALUES  (@title,@content,@caid)
    end
    
    exec news_insert '这是标题','这里是内容',22
    
    -- =============================================
    -- Author:		<李鹏>
    -- Create date: <2011-10-25 15:23>
    -- Description:	< 修改新闻>
    create proc news_Update
    @title varchar(200),@content text,@caid int,@id int
    as
    begin
    UPDATE    news
    SET              title = @title, [content] = @content, caId = @caid
    where id=@id
    end
    
    -- =============================================
    -- Author:		<李鹏>
    -- Create date: <2011-10-25 15:43>
    -- Description:	< 删除新闻>
    create proc news_Delete
    @id int
    as
    begin
    --先删除该新闻下的评论
    delete comment where newsid=@id
    --再删除新闻本身
    delete from news where id=@id
    end
  • 相关阅读:
    用java抓取网页信息!
    WPF之Binding对数据的转换(第五天)
    WPF读书笔记 x名称空间详解(第二天)
    WPF的UI布局(Layout)WPF读书笔记(第三天)
    WPF 数据绑定Bingding基础(第四天)
    WPF读书笔记(第一天)
    HelloWin程序(窗口与消息)
    django创建数据库表方法
    OpenSSH利用处理畸形长度密码造成的时间差,枚举系统用户(CVE20166210)
    ldap匿名访问测试脚本
  • 原文地址:https://www.cnblogs.com/iceicebaby/p/2216304.html
Copyright © 2020-2023  润新知