Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: Beginning PHP 5.3
This is the forum to discuss the Wrox book Beginning PHP 5.3 by Matt Doyle; ISBN: 978-0-470-41396-8
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP 5.3 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 29th, 2010, 10:17 AM
Registered User
 
Join Date: Nov 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Concept of NULL

Hy Guys,

Beginning with mysql. I am not able to grasp the concept of NULL. Check flickr screen-shots. In it when I specifically declared 'name' field to be NOT NULL. When i run the 'desc test' table command, the table description shows default value for name field to be NULL.Why is that so?

From what I have read about NULL, it connotes a missing or information that is not applicable. So when I declare a field to be NOT NULL it implies (as per my understanding) that user must enter a value for the name field else the DB engine should generate an error i.e. record will not be entered in DB. However when i run 'insert into test value();' the DB engine enters the record in table. Check flickr screen-shot(second-one).

FLICKR LINKS *declare_not_null* http://www.flickr.com/photos/55097319@N03/5302758813/

*empty_values* Check the second screenshot on flickr

Q.2 what would be sql statement to drop a primary key from a table's field. If I use 'ALTER TABLE test drop key id;' it gives the following:

ERROR: Incorrect table definition; there can be only one auto column and it must be defined as a key.

Thanks for your help.
  #2 (permalink)  
Old December 31st, 2010, 05:43 PM
Registered User
 
Join Date: Nov 2010
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Angry Surprise !!! no answer..........

  #3 (permalink)  
Old January 11th, 2011, 08:49 PM
Registered User
 
Join Date: Jan 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by rseni View Post
Hy Guys,

Beginning with mysql. I am not able to grasp the concept of NULL. Check flickr screen-shots. In it when I specifically declared 'name' field to be NOT NULL. When i run the 'desc test' table command, the table description shows default value for name field to be NULL.Why is that so?

From what I have read about NULL, it connotes a missing or information that is not applicable. So when I declare a field to be NOT NULL it implies (as per my understanding) that user must enter a value for the name field else the DB engine should generate an error i.e. record will not be entered in DB. However when i run 'insert into test value();' the DB engine enters the record in table. Check flickr screen-shot(second-one).

FLICKR LINKS *declare_not_null* http://www.flickr.com/photos/55097319@N03/5302758813/

*empty_values* Check the second screenshot on flickr

Q.2 what would be sql statement to drop a primary key from a table's field. If I use 'ALTER TABLE test drop key id;' it gives the following:

ERROR: Incorrect table definition; there can be only one auto column and it must be defined as a key.

Thanks for your help.
First off, I cannot see the screen shot due to the image being private.

As for the field being set to NOT NULL and its default is NULL: A field will always have a NULL value as it's default unless predefined as something else. Now when you run your insert command I believe the SQL prompt tries to avoid an error by placing an empty string value in the field instead of the actual NULL value if it is a string field. It would be 0 if it was a number field. The only way to get the error is if you put in NULL in the insert statement like so:
Code:
insert into test value(NULL);
As for your second question. If you are trying to make an auto incrementing field a non key, you cannot. An auto increment field must be the primary key. The only way you can remove it is by either dropping the column or changing it to being non auto increment.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Implementing interface concept in C# gowrisankar C# 2005 4 January 18th, 2010 07:50 PM
XMail Concept (Help) gmbalaa General .NET 1 August 26th, 2007 01:57 PM
shopping cart concept sarah lee ASP.NET 1.0 and 1.1 Basics 1 October 16th, 2006 12:29 PM
Design Concept shazza Biztalk 1 August 23rd, 2006 09:54 AM
Is there "Floating ToolBar" concept in C# ? kishore_peddi C# 1 April 15th, 2004 01:58 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.