We help IT Professionals succeed at work.

SQL Filestream table with relationship one to many

520 Views
Last Modified: 2012-02-08
Hello everybody,

I am trying to implement Filestream in my database.
I have one Post and each post can have many attachments,

so the relationship must be 1post - many attachments but the only relationship I can create is 1 - 1, can someone help me?

here is a picture of the database diagram:
Database diagram
In advance, many thanks :D
Comment
Watch Question

AnujSQL Server DBA
Top Expert 2011

Commented:
You have to combine both AttachmentID and PostID as your Primary Key (or Coposit key).
This will allow Multiple attachments for a single PostID.
Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
you can surely right-click that link, and edit it?!

Author

Commented:
Thank you for your reply anujnb.

this is what I did:
I deleted current relationship
I made both AttachmentID and PostID as PrimaryKey
I creted a new relationship from Post.PostID to Attachments.PostID

result: The same, relationship 1 to 1
I attach the image below:
Any idea?
Database diagram 2
Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
no , only attachmentid shall be primary key in the attachments table.
change that back.

can you double-click on the relation, and post that screen?

Author

Commented:
Thanks for the reply angelIII

I try right clicking the relationship, the only option SSMS gives me is: "Delete Relationship from Database".

I attach a picture of the properties of the relationship
Relationship properties
Guy Hengel [angelIII / a3]Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009

Commented:
I think you draw the relationship the wrong way, you have to do it the other way round.
it's not the same result if you drag/drop from post table to attachments or the other way round.
please try it out...

Author

Commented:
It's impossible to create a wrong way relationship cause the drag-and-drop only activates if the row you are dragging is PK so I can only take Post.PostID to Attachment.PostID

thanks anyway, any other idea?
Billing Engineer
CERTIFIED EXPERT
Most Valuable Expert 2014
Top Expert 2009
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thank you, this link helped me a lot :D

Gain unlimited access to on-demand training courses with an Experts Exchange subscription.

Get Access
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Empower Your Career
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.