School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,131 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,057 people online right now. Registration is fast and FREE... Join Now!




Possible to delete just a value?

 

Possible to delete just a value?

aklo

6 Nov, 2009 - 05:28 PM
Post #1

D.I.C Head
**

Joined: 23 Jan, 2009
Posts: 52



Thanked: 2 times
My Contributions
Is it possible to delete just a value (cell) in a database?

Even if it is possible, it is not a good way to leave a cell empty right?




User is offlineProfile CardPM
+Quote Post


Martyr2

RE: Possible To Delete Just A Value?

6 Nov, 2009 - 10:04 PM
Post #2

Programming Theoretician
Group Icon

Joined: 18 Apr, 2007
Posts: 7,307



Thanked: 838 times
Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions
Yeah you can delete just a cell in a database. Some "purists" that insist on having their databases in what is called 6th Normal form (fully normalized) would say that is bad. But I am a strong believer that you VERY RARELY want a database fully normalized to the 6th level. A database should at least be normalized to 3rd normal form with possibility of going to 4th or maybe 5th if business requires it.

So in short, yes, you can delete just a cell by updating the row and setting the field to NULL (if the field is declared to accept nulls) or an empty string.

CODE

update mytable set myfield = NULL where id = 3


As for good or bad, I say it is fine as long as it is not a critical field (a key of some kind) and is considered an "optional information field". But don't let the purists scare you too much, a 3rd normal form table is just fine and even has its advantages over higher forms (like they produce shorter easier query statements typically).

smile.gif
User is offlineProfile CardPM
+Quote Post

baavgai

RE: Possible To Delete Just A Value?

7 Nov, 2009 - 03:10 AM
Post #3

Dreaming Coder
Group Icon

Joined: 16 Oct, 2007
Posts: 4,351



Thanked: 411 times
Dream Kudos: 550
Expert In: C, C++, Java, C#, ASP.NET, PHP, Perl, Python, Oracle, SQL Server, MySql, HTML, JavaScript, Lua, Cheese

My Contributions
QUOTE(aklo @ 6 Nov, 2009 - 07:28 PM) *

Even if it is possible, it is not a good way to leave a cell empty right?


Like Martyr said. Only to add, that's why they invented null. Those "purists" are hard to find in the real world. Real world data is just too damn messy. The null allows an explicit designation of empty. If that field shouldn't be empty, it will have a constraint that prevents empty.

Again, in the real world, not null fields will often just get filled with crap by the user. I recently saw a required text field filled with "NA" for the most part. Phone numbers that are all zeros, that sort of thing.

User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 02:39PM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month