#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2000
    Posts
    1
    Rep Power
    0
    Hey,

    I am wondering how you check if an element in a table CAN be null or not (ie if it was declared with the NOT NULL directive or not). How do you do this??

    Thanks, Tom
  2. #2
  3. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    Method 1:

    Issue a "show columns from table" query, parse through each row looking for the column in question, then see if that row also has not null in it.

    Method 2:

    Insert a null value and see if it works. Then delete it if neccessary.

    INSERT INTO test (column_name) VALUES (null);

    Notice no quotes around null.

    ---John Holmes...
  4. #3
  5. No Profile Picture
    Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Colchester, England
    Posts
    131
    Rep Power
    14
    To display the table definitions from the MySql command prompt:
    USE databasename;
    DESC tablename;

    Andy J
  6. #4
  7. Banned (not really)
    Devshed Supreme Being (6500+ posts)

    Join Date
    Dec 1999
    Location
    Brussels, Belgium
    Posts
    14,642
    Rep Power
    4492
    "desc tablename" and "show columns from tablename" give the same output, btw.

    Any command you can give from the command line can be given in a mysql_query() command.

    ---John Holmes...

Similar Threads

  1. Two Steps Query ?
    By Fabiop in forum MySQL Help
    Replies: 5
    Last Post: February 16th, 2004, 11:16 AM
  2. Replies: 5
    Last Post: January 11th, 2004, 08:19 PM
  3. Design Problems- extra relationships
    By wordracr in forum Database Management
    Replies: 33
    Last Post: January 11th, 2004, 06:42 AM
  4. syntax error
    By DQSJR in forum MySQL Help
    Replies: 2
    Last Post: December 31st, 2003, 01:28 PM
  5. design advice needed please.
    By LightningWeb in forum MySQL Help
    Replies: 1
    Last Post: December 20th, 2003, 01:22 PM

IMN logo majestic logo threadwatch logo seochat tools logo