Click here to Skip to main content
15,887,821 members
Home / Discussions / Database
   

Database

 
QuestionSelect Exact Day Pin
Agweet11-Sep-08 22:16
Agweet11-Sep-08 22:16 
AnswerRe: Select Exact Day Pin
dojohansen12-Sep-08 1:21
dojohansen12-Sep-08 1:21 
GeneralRe: Select Exact Day Pin
Agweet12-Sep-08 1:59
Agweet12-Sep-08 1:59 
QuestionNeed some help with deleting process Pin
MarkB77711-Sep-08 22:15
MarkB77711-Sep-08 22:15 
AnswerRe: Need some help with deleting process Pin
Blue_Boy11-Sep-08 22:22
Blue_Boy11-Sep-08 22:22 
GeneralRe: Need some help with deleting process Pin
MarkB77711-Sep-08 23:17
MarkB77711-Sep-08 23:17 
GeneralRe: Need some help with deleting process Pin
Blue_Boy11-Sep-08 23:42
Blue_Boy11-Sep-08 23:42 
GeneralRe: Need some help with deleting process Pin
dojohansen12-Sep-08 1:31
dojohansen12-Sep-08 1:31 
Not sure if that was intentionally evil but TRUNCATE will remove ALL the data from the table...

The reason you are getting the error is because SQL Server is enforcing referential integrity. It's easiest to explain in the context of a simple example, so imagine you have book and author tables, and for the sake of simplicity let's assume a book can have only one author, but an author can write many books. The way this would be implemented in a relational database is by defining a foreign key column in the Books table that point to an author, say AuthorID. Now if you delete an Author there may be Book records that refer to that author, and this is generally considered a bad thing. Depending on your scenario it might make sense to decide that if an author is deleted, so should all the books by that author be. This is called CASCADE DELETE and can be configured in SQL Server so your code can just delete one or more Author records, leaving it to SQL Server to also delete the related books. In other cases it might make more sense to UPDATE the Books table and perhaps set NULL in the AutorID column, or sometimes even to transfer the association so it refers to another entity (though in our example it makes no sense to change the author of books).

SQL server only enforces referential integrity for relations that are so configured. You CAN change the setup and it will allow you to leave data referring to non-existing data, but of course this is seldom a good idea. Usually it is best to define all your relations in the database and enforce integrity everywhere. This will help you spot errors much earlier in the development and prevent errors in your code from corrupting the data, but may of course cause blocking bugs if you do not perform adequate testing.
AnswerRe: Need some help with deleting process Pin
razov12-Sep-08 0:11
razov12-Sep-08 0:11 
GeneralRe: Need some help with deleting process Pin
MarkB77712-Sep-08 0:17
MarkB77712-Sep-08 0:17 
GeneralRe: Need some help with deleting process Pin
razov12-Sep-08 0:37
razov12-Sep-08 0:37 
GeneralRe: Need some help with deleting process Pin
MarkB77712-Sep-08 0:44
MarkB77712-Sep-08 0:44 
GeneralRe: Need some help with deleting process Pin
razov12-Sep-08 0:50
razov12-Sep-08 0:50 
AnswerRe: Need some help with deleting process Pin
nelsonpaixao12-Sep-08 14:36
nelsonpaixao12-Sep-08 14:36 
QuestionHow to get the first and last record in every group? Pin
followait11-Sep-08 20:18
followait11-Sep-08 20:18 
AnswerRe: How to get the first and last record in every group? Pin
Blue_Boy11-Sep-08 20:43
Blue_Boy11-Sep-08 20:43 
GeneralRe: How to get the first and last record in every group? Pin
followait11-Sep-08 21:53
followait11-Sep-08 21:53 
GeneralRe: How to get the first and last record in every group? Pin
Blue_Boy11-Sep-08 22:17
Blue_Boy11-Sep-08 22:17 
GeneralRe: How to get the first and last record in every group? Pin
followait12-Sep-08 6:15
followait12-Sep-08 6:15 
GeneralRe: How to get the first and last record in every group? Pin
followait12-Sep-08 17:20
followait12-Sep-08 17:20 
QuestionNested Stored Procedure Pin
jonhbt11-Sep-08 19:51
jonhbt11-Sep-08 19:51 
AnswerRe: Nested Stored Procedure Pin
Ashfield11-Sep-08 20:55
Ashfield11-Sep-08 20:55 
AnswerRe: Nested Stored Procedure Pin
Mycroft Holmes11-Sep-08 20:58
professionalMycroft Holmes11-Sep-08 20:58 
GeneralRe: Nested Stored Procedure Pin
Venkat Eswaran12-Sep-08 7:02
Venkat Eswaran12-Sep-08 7:02 
GeneralRe: Nested Stored Procedure Pin
Mycroft Holmes12-Sep-08 12:47
professionalMycroft Holmes12-Sep-08 12:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.