Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 140681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:39:17+00:00 2026-05-11T07:39:17+00:00

I’m writing a very simple blog engine for own use (since every blog engine

  • 0

I’m writing a very simple blog engine for own use (since every blog engine I encountered is too complex). I want to be able to uniquely identify each post by its URL which is something like /2009/03/05/my-blog-post-slug. To accomplish it in the data tier, I want to create a compound unique constraint on (Date, Slug) where Date is only the date part (ignoring the time of day) of the composition date. I have a few ideas myself (like another column, probably calculated, to hold only the date part) but I came to SO to know what’s the best practice to solve this problem.

I doubt SQL Server version matters here, but for the records, I’m on 2008 Express (I appreciate a more portable solution).

Table schema:

create table Entries (     Identifier int not null identity,     CompositionDate datetime not null default getdate(),     Slug varchar(128) not null default '',     Title nvarchar(max) not null default '',     ShortBody nvarchar(max) not null default '',     Body nvarchar(max) not null default '',     FeedbackState tinyint not null default 0,     constraint pk_Entries primary key(Identifier),      constraint uk_Entries unique (Date, Slug) -- the subject of the question ) 

Selected Solution:

I think marc’s solution is more appropriate, considering this question is about 2008. However, I’ll go with the integer method (but not with INSERTs, as it does not ensure the integrity of data; I’ll use a precomputed integer column) since I think it’s easier to work with the integer thing from the client (in the query).

Thank you guys.

create table Entries (     Identifier int not null identity,     CompositionDate smalldatetime not null default getdate(),     CompositionDateStamp as cast(year(CompositionDate) * 10000 + month(CompositionDate) * 100 + day(CompositionDate) as int) persisted,     Slug varchar(128) not null default '',     Title nvarchar(max) not null default '',     ShortBody nvarchar(max) not null default '',     Body nvarchar(max) not null default '',     FeedbackState tinyint not null default 0,     constraint pk_Entries primary key(Identifier),     constraint uk_Entries unique (CompositionDateStamp, Slug) ) go 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:39:18+00:00Added an answer on May 11, 2026 at 7:39 am

    Well, in SQL Server 2008, there’s a new datatype called ‘DATE’ – you could use that column and create an index on that.

    You could of course also add a computed column of type ‘DATE’ to your table and just fill the date portion of the DATETIME column into that computed column, make it PERSISTED, and index it. Should work just fine!

    Something like that:

    ALTER TABLE dbo.Entries    ADD DateOnly as CAST(CompositionDate AS DATE) PERSISTED  CREATE UNIQUE INDEX UX_Entries ON Entries(DateOnly, Slug) 

    Marc

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.