Friday, July 30, 2010

Make a blogging application

--The following query tells you how to make a small blog with comment feature.
--create table articles
CREATE TABLE [dbo].[articles]
(
[id] [int] IDENTITY(1,1) NOT
NULL,
[title] [varchar](100) NOT
NULL,
[article] [text] NOT
NULL,
)
--create table comments
CREATE TABLE [dbo].[comments]
(
[id] [int] IDENTITY(1,1) NOT
NULL,
[article_id] [int]
NULL,
[title] [varchar](50)
NULL,
[comment] [text]
NULL,
)
--to see an article with all its comment
select 'articles' as
rowtype
, articles.
id
, articles.
title
, articles.
article
from
articles
where articles.id =
1
union all
select
'comments' as
rowtype
, comments.
id
, comments.
title
, comments.
comment
from
articles
inner
join
comments
on comments.article_id = articles.
id
where articles.id =
1
order
by
rowtype

No comments:

Post a Comment