Solved

Date field doesn't seem to work in a multi column primary key

Posted on 2014-02-12
5
245 Views
Last Modified: 2014-02-12
In a new table, I setup a multi-column primary key consisting of a CustomerId (int) field, SalesId (int) field and a MailingDate (date) field. However, this is not preventing me from adding duplicate records into the table.

I suspect that a column of data type date cannot be used in a multi-column key or that there is a time component to this field that is preventing uniqueness?

If true, can someone suggest an alternate method of preventing duplicate records in a table with the same Customer Id, Sales Id and Mailing Date.

Thanks.
0
Comment
Question by:dwcummings
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 40

Accepted Solution

by:
Kyle Abrahams earned 500 total points
ID: 39854132
you could break out the date field to three month / day / year int columns.

Why include the mailing date as a primary field at all though?
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 39854155
I concur with above.
You could have one field with DATE datatype instead of DAYTIME for the primary key part. However if the time portion is needed for other processes you will need two field.
0
 
LVL 3

Author Closing Comment

by:dwcummings
ID: 39854215
The mailing date is the only unique column in the table, as customers can have multiple mailings from the same salesperson, but not on the same date. I like the idea of breaking out the date into 3 int columns, but have decided to add an additional column to the table to force uniqueness - that being a mailing id field. I don't need a time component.

Thanks for the help.
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 39854219
There is nothing that prevents a date or datetime column from participating in the primary key or other indexes.  If it's a datetime column, then the entire time would be considered, not just the date.
0
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 39854291
Mail ID would be the way to go, this way oyu have a reference to all other info about that mailing.  Just my 2 cents.
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

732 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question