Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    MYSQL


SuperbHosting.net have generously sponsored dedicated servers to ensure a reliable and scalable dedicated hosting solution for BigResource.com.





CREATE TABLE :: Null And Not Null


I recently created a new table in a database and wanted some fields to accept nulls (NULL) and others to not accept nulls (NOT NULL). The table was built correctly, however, when I went to edit a row in the Query Window of MySQL Browser it allowed me to enter in the row when the NOT NULL fields had no values attached to them - this should fail and stop me from entering a row.

Here is the script for the table I created;

CREATE TABLE SLG (
SLG_ID int(11) NOT NULL auto_increment,
SLG_CODE CHAR(1) NOT NULL,
SLG_DESCRIPTION VARCHAR(255) NOT NULL,
SLG_DATE_CREATED DATETIME NOT NULL,
SLG_DATE_MODIFIED DATETIME NOT NULL,
PRIMARY KEY (SLG_ID)
);

When I apply the changes in this window it just enters NULLS into all the other fields. Is this a Query Browser issue. I tried doing the same with an INSERT statement and received the same result.

Also - related to creating a table - is it possible to create global Defaults on a database and then reference those in the DEFAULT statement of the CREATE TABLE command. MS SQL has a system function that can be executed after a table is created to bind a global default to a specific column.




View Complete Forum Thread with Replies

Related Forum Messages:
MySQL 4.0.17 Data Scrambles, Not-null Fields Become Null, Etc.
I'm having the most bizarre problem with PHP/MySQL that I've ever
faced and it's an urgent matter (of course) to try to fix it ASAP.

We have one record inserted into a table with 75 columns, whereby half
of the columns are not-null, but for some bizarre reason, the fields
are null. The rest of the columns that are null are completely
scrambled (e.g. "first_name" is in "address2", "fax" is in "url", "url"
is in "last_name", etc.)

This just recently occurred and seems to have no history otherwise. It
occurred sometime on Saturday when the record was inserted but logs
indicate no unusual activity at that time.

Has anyone seen this before and found a way to prevent it from
occurring again?

View Replies !
Incorrect Integer Value: 'NULL' For Column Even If NULL Is Allowed
mysql> desc my_table;
+------------+---------------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+---------------------+------+-----+---------+-------+
| id | varchar(19) | NO | PRI | | |
| value1 | int(11) | YES | | NULL | |
| value2 | int(11) | YES | | NULL | |
+------------+---------------------+------+-----+---------+-------+

I want to import data from a file that looks like this:
9bcd6f7b47a30fb8_01;NULL;NULL

With following command:
mysql> load data infile 'filename' into table my_table fields terminated by ';';

And get following error:
ERROR 1366 (HY000): Incorrect integer value: 'NULL' for column value1'' at row 1

So the system denies me importing NULL values into a field where NULL is allowed.

View Replies !
Is Null Clause Takes A Lot Of Time But Is Not Null Statement Not
i have a query which takes 1 and half minute to fully execute. This query is following which return 2 records

select o.id, o.number, o.timest, o.receiptno, o.canedit, o.sessionid, o.voidorder, o.cashchange,p.amount from orders o left join payments p on (o.id=p.oid) where p.amount is null

but if i remove the 'not' from where clause then it takes a fraction of seconds. query is following which takes fraction of second and it returns 3920 records

select o.id, o.number, o.timest, o.receiptno, o.canedit, o.sessionid, o.voidorder, o.cashchange,p.amount from orders o left join payments p on (o.id=p.oid) where p.amount is not null

View Replies !
Getting Null Values From A TEXT NOT NULL Field
I have created a table with a field labeled Description which is a TEXT field which does not allow null values. It's defined with

Description TEXT NOT NULL,

However, when empty strings are stored in the Description field, I get NULLs back when querying the database. I'm writing an ASP application which connects to the MySQL database through ADODB. The MySQL version is 5.0.45. The engine is InnoDB.

View Replies !
Insert From Python Program Create Only NULL Vals
I have a small Python program to insert data into my MySql tables. The program inserts records into the table but when I check the table it shows the correct number of records but only NULL values in the fields. I have tried it on Linux as well as on Windows version of MySQL but the same result.

Any idea why this would happen?

View Replies !
Insert Null To Not Null Column
I have build a replication environment in my environment. the master is MySQL 5.0.24a-standard-log and the slave is 5.1.30-log. the configuration is not the same between them.

I have found a replicaiton error in the slave today says: .....

View Replies !
NULL And NOT NULL Settings
I have a MySQL table that stores name and age of a person. The name field needs to have a value; the age field is optional.I'm quite confused now with the NULL and NOT NULL settings... It seems that neither one does what I want (rejecting an INSERT query where the name field is empty)...So what exactly do I have to do?

View Replies !
VARCHAR Null/Not Null
I'm having a problem with a table that is already created - I want insert attempts to FAIL when the column for 'firstname' is empty (a VARCHAR field). Currently, the column is set to Null=YES and a Default of 'NULL'. This allows records to be inserted with no 'firstname' value (NULL appears in the column). If I change it in phpmyadmin 'structure' to Null=NO and Default of [empty field] then it allows records to be inserted with no 'firstname', and 'firstname' shows empty in the column

View Replies !
PK Field Not Null Is Being Null
I m newbie. I made a MySQL database table and in the primary key field I set the data type VAR CHAR.I also set it not null .BUT still I can insert blank values in this PRIMARY KEY field. If I just blank my primary key field by this query- Insert Tablename Values ('','','','','',''); (if my table has 6 fields).HOW IS IT POSSIBLE. How can PK field allow blank value when I set not null. HOW TO SOLVE IT.

2. I use a MySQL GUI Tools from http://dev.mysql.com/downloads/. In Table viewer of Query browser, each time I insert the first field, it sets the datatype to INTEGER,NOT NULL, AUTO INCREMENT. But I change it to VARCHAR as needed. Do I have to/should use Integer type in PK field and can Varchar be incremented.

3.Can I set user privilege to a particular row (on a particular PK); HOW?

4. Is it correct/incorrect that the name of the foreign key has to be the same as the name of the corresponding PK. I saw that in MySQL I can easily change the FK name to anything else and then just make a reference of FK to the PK.

5. How can I make a one-to-one relationship in MySQL;

View Replies !
Setting Null To Not Null How?
i have a mysql table.. (duh!)

a field in it is set to null and i want to unset it to make it not null.

how do i do that ? by default it takes null values (its weird.. default is null while null column is a no.. so it cant take null values!)

View Replies !
ALTER TABLE :: Not Null
I made a table this way:

mysql>create table tblCourses (courseCode char(30) primary key,
courseDescription char(50));

Now I realize that I forgot to enforce that both fields will not be null.
So I tried this:

mysql> alter table tblCourses (courseCode not null, courseDescription not
null);

but I got this result:

ERROR 1064: You have an error in your SQL syntax. Check the manual that
corresponds to your MySQL server version for the right syntax to use near
'(courseCodenot null, courseDescription not null)' at line 1

Do I need to drop the table and start over? Or how could I add this?

View Replies !
Not Null When Creating Table
I just started with MySql and I'm pretty excited. When I create a table, which attributes of the entities should be created with NOT NULL? I'm aware that the primary can't have NOT NULL, but what about TEX and all the other data types?

View Replies !
How To Delete NULL From A Table
I have a table that has NULL values and need to delete them. This is a part of the table that has NULL data

ORDER ID DATE IDcard
'506', '10', '22112007', 'm3625184.326'
'506', '10', 'NULL', 'm3625184.326'
'506', '10', '22112007', 'm3625184.326'
'506', '10', 'NULL', 'm3625184.326'
'506', '11', '22112007', 'm3625184.326'
'506', '11', 'NULL', 'm3625184.326'
'506', '11', '22112007', 'm3625184.326'
'506', '11', 'NULL', 'm3625184.326'

I try to do it this way :
DELETE FROM r506_1x WHERE fentrada = 'NULL'

View Replies !
How Can I Use NOT NULL Table Column Definition?
I have table with columns which has NOT NULL definition. What can I do to be ensure that update or insert will not modify table with empty values?

MY EXAMPLE:

if($zm=='')
$zm=null ;

or what can I do?

How can I use NOT NULL table column definition? or what NOT NULL definition is for?

View Replies !
ALTER TABLE :: Unsigned And Null
What would be the ALTER TABLE command for making a field key MUL and making another field type unsigned?

View Replies !
Sparse InnoDB Table To Use NULL?
If a varchar(20) column is not going to have a value at least half of the time, should it have a default value of NULL or NOT NULL?

I will have a MySQL 4.1 InnoDB table with about 12 columns. 8 of these are going to be varchar(20). Usually only a few of these fields will be populated (but which ones are pretty random). The table will mostly be used for inserts, and around 200,000 inserts a month.

View Replies !
Joining Table With Null FK Rows
I've got this query:

DROP VIEW `pmd_manf2`.`vw_ProductFirmware`;
CREATE VIEW `pmd_manf2`.`vw_ProductFirmware` AS
SELECT p.Name, fw.FirmwareID, fw.DateCreated, fw.FileSize, fw.Prod_ProductID, CONCAT(pf.FirmwareVersion, '.', p.FirmwareVersion) AS Version FROM Firmware as fw
JOIN Products AS p ON p.ProductID = fw.Prod_ProductID
JOIN ProductFamilies AS pf ON pf.ProductFamilyID = p.ProdFamily_ProductFamilyID
JOIN Customers AS c ON c.CustomerID = p.Cust_CustomerID;

p.Cust_CustomerID can be null (not all products are associated with a customer)
When I exclude:
JOIN Customers AS c ON c.CustomerID = p.Cust_CustomerID;

the query runs fine, when I add
JOIN Customers AS c ON c.CustomerID = p.Cust_CustomerID;

I don't get any results. I've read up on JOIN and tried the different JOIN flavors but I can't get around this problem. Do I have an error in my query or is it not possible to join a table that won't have a match for every row in the parent?

View Replies !
Accepting Values As NULL When Not In Another Table
Is it possible to perform a SELECT query on multiple tables and simply accept one of the values as NULL if not in another table rather than the whole query failing?

For instance, if "rec_id" exists in "table_1" for certain but it is uncertain if it exists in "table_2", is it possible to return the query with a variable assignment stating whether "rec_id" was or wasn't found in "table_2"?

I am hoping I can do this without a LEFT OUTER JOIN as the query is fairly complex and involves five different tables. Whenever results are fetched I simply need to know if rec_id is or isn't in table_2 if it is found in table_1.

As there are frequently over 10,000 result rows returned it wouldn't be sound to put this into a seperate loop that queries with each rec_id to see if it is in table_2.

I have tried "SELECT table_1.rec_id, table_2.rec_id FROM table_1, table_2 WHERE table_2.rec_id=table_1.rec_id OR table_2.rec_id IS NULL" but this returns no records.

View Replies !
Check For NULL Fields In All Columns Of A Table
I am populating tables via programs and load data infile command, For my tables all the fields should not be null. James told me the syntax for checking null fields,

SELECT COUNT(*) FROM table WHERE col1 IS NULL;

This command is working for a single column only.How do I check for all the columns of my table in a single command.

View Replies !
Extra NULL Columns Or A Separate Table?
I have a table that can hold two different types of users. One type of user has settings that can change, the other user does not. There are only two different settings for the one user (so only two extra columns) but they will NULL for the user that cannot change them.

My question is, is it more efficient to just put the settings in a separate table and just join on the user table? Or is it better to put NULLs in the users table for those who will not be able take advantage of the extra features?

View Replies !
Load Null Values In Table Through LOAD FILE
I'M TRYING TO LOAD FILE WHICH HAS NULL VALUES FOR SOME COLUMNS AT THE FIRST ROW.IT Says "Incorrect Date Value for the column" as it has null values

View Replies !
Load Null Values In Table Through LOAD FILE
I'M TRYING TO LOAD FILE WHICH HAS NULL VALUES FOR SOME COLUMNS AT THE FIRST ROW . IT Says "Incorrect Date Value for the column" as it has null values.

View Replies !
LIKE And IS NOT NULL
Are the LIKE and IS NOT NULL options available in MySQL - these 2 options
are availble in Access and MS SQL.

LIKE is for searching using wildcards - e.g WHERE Name Like 'AD%'.

View Replies !
Getting The Null
I have two tables to compare
Code:
Schedule of Subject(table 1) previous subject taken(table 2)
Semister ID Subj ID | Semister ID Subj ID
1 1 | 1 1
1 2 | 1 2
1 3 | 1 3
1 4 | null null
1 5 | null null



My PK for this should be Semister ID.

My table 2 has only 3 records, so obviously if I compare
table2 from table1 (which has 6 records), table 2 should show the null value because it has no record for the following semister and subjects.

View Replies !
NULL/NOT NULL
I'm drawing a blank when it comes to using NULL/NOT NULL in my tables... can someone refresh my memory about this option in laemen terms. Also how or why does the field with this option have "NULL" entered in the field as the default value?

View Replies !
NULL Or Zero
`timestampLastFailedLogin` int(11),
If there is no value(field was never accessed or used) should I leave it with NULL value
or should I give it 0 as default value as follows?

`timestampLastFailedLogin` int(11) UNSIGNED NOT NULL DEFAULT '0'

View Replies !
WHERE A OR B OR C IS NOT NULL
I am trying to sort my recordset so that records will only display if certain columns contain information. I am unsure of the syntax on this. My first two columns will always be populated with data, but I only want to display the record if any one of the rest of the columns contain data. I know that .Code:

SELECT *
WHERE a OR b OR c IS NOT NULL

is not quite right.

View Replies !
Using NULL Vs 0
I have a DB i MySQL that uses many int(1) type fields. I store there some time value 0 or NULL.
My question is which solution is faster from DB point of view?
Should I store NULL for all those fields or is "0" better solution?
Which one takes less space and time to process?

View Replies !
NULL And NOT NULL
I understand the meaning of NULL, but I don't understand its usage. For example, a field declared to be NOT NULL, but has a NULL value. Or when a field is declared to be NULL, and yet values can still be placed into it. I don't understand the logic behind this.

View Replies !
IS NOT NULL
I tried below mentioned sql statement

mysql> SHOW COLUMNS FROM Country WHERE `Default` IS NOT NULL;


and suprinsgly it even list down those record as well where coloumn 'default' is NULL

Note : In the preceding statement, the column name (Default) must be given as a quoted identifier because it is a reserved word.


Any specific reason why it produced record having value as NULL, i tried somewhat similar to my own table , and it works fine for my other table.

View Replies !
WHERE Id NOT IN (NULL)
CREATE TABLE t (id INTEGER PRIMARY KEY);
INSERT INTO t SET id=1;
SELECT * FROM t WHERE id NOT IN (2); # one row
SELECT * FROM t WHERE id NOT IN (NULL); # empty set

This is a big surprise, since in my mind 1 is not in (NULL).

Here's another strange difference:

SELECT (1 IN (NULL)); # (NULL)
SELECT (1 IN (2)); # (0)

View Replies !
Null OR Value
how can I write a query that will return results that are either null or a specified value e.g.

e.g something like

SELECT * FROM Table 1 where ID = null OR 5

View Replies !
Null Vs Not Null
I create a field in a table as a "Not Null" would this prevent a new record to be created unless that field is properly filled?
I'm playing around with a test website and I tried leaving blank a "Not null" field but the record was created anyway with that field empty.
Maybe I'm not understanding the Null vs Notnull stuff correctly?
If so, how would one restrict the creation of new records unless a not null field contains valid (or data at all) data?

View Replies !
What Should Be NULL Is Zero
I am collecting user feedback via an HTML form and sending it to a DB via a PHP form handler. My problem is that values that should be NULL are showing up in the DB as zero.

When a user skips a question, I want the value for that field to be NULL. In the form, I set the variables used to capture the user's choices to default to NULL (not enclosed in quotes). All the PHP handler does is gather the submitted values and send them off to the database. When I echo the variables from the form handler, they are NULL. In the database, the fields are defined as INT(1) with a NULL default value. But when the values (which should be NULL) are submitted to the DB via the form handler, the resulting fields are zero.

(I have also tried setting the form's default values to "" and '' with the same result.)

What can I do to make these values NULL?

View Replies !
NOT NULL Vs. NULL
I have a table that's populated by a form. There are some fields that are optional. Should I send empty strings to a NOT NULL column or should I set the column as NULL and send nothing at all?

Am I right in interpreting the meaning of NOT NULL by saying: NOT NULL means an INSERT will fail if the corresponding field is left out of the query?

View Replies !
Null Or Not Null
I am setting up my db, and am reading a great book on all of this, but am confused on exactly when to use null and not null.

View Replies !
Using NULL
I was wondering is it good practice to use NULL for unknown values?
In the PHP forum sticky it says:
2) Declare all of your columns NOT NULL unless you need to store NULL values (NULL is not the same as 0 or the empty string). If you need to store NULL, you'll know. Again, NOT NULL saves space and speeds things up.
In the fields I am thinking of storing NULL, I could instead use empty string in the CHAR fields, and 0 in the numeric fields. However using NULL would make life a bit easier, and is probably more readable.
Should I use NULL? Or, is it better practice to avoid it where possible and use 0/""? Or, am I misunderstanding use of NULL altogether?

View Replies !
Not Null
I can't seem to find a comprehensive or accurate answer on this subject.

Is it more work and/or overhead for mysql to mark a column as not null? IE, should I keep columns as NULL whenever possible?

If the column is allowed to be null but I also provide a default value, will the default be chosen if no value is provided?

If the column is not allowed to be null and I don't provide a default value, will a default be chosen? IE 0, false, "", etc

View Replies !
Not Null Not Taking
Why would some innodb's not take a 'no null' for a field? Has anyone
experienced anything like this?

View Replies !
Null Defaults
If I have setup mysql with strict_trans_tables,
will MySQL allow "null" defaults in "not null" columns?
If the answer is yes, will that information be reflected when I ask for
metadata (column information, etc.)?
Currently, when I ask for metadata information, not-null columns will
return a default of "empty string".

As additional information, I currently use 5.0.21-community-nt

View Replies !
Sort NULL Last
I have a mysql query, "SELECT * FROM task ORDER BY duedate ASC", where
"duedate" is a unix_timestamp and can be NULL. I want any NULL results
to be at the end of the list, how might I do this?

View Replies !
When To Use NULL As Default Value
I pretty much set a fields default value to NULL if it not a "required" field in my app.

View Replies !
When To Use 'NOT NULL' In Tables
My database receives HTML form values (text, I don't store binary files in
any of my tables).When is it adviseable to create a table column with NOT
NULL?I make a habit of having all my table columns this way but wonder if
I am just putting additional overhead (however small) on the server and
getting zero advantages.

View Replies !
Enum Set Null Value
I am using mysql db.The table structure is given below ....

View Replies !
Count() Null=1
Whenever I use the aggregate function count with a left join the NULL values like to COUNT() themselves as 1. Does anyone know what's causing this or how to fix it?

View Replies !
Dealing With NULL
Is there a why to instruct MySQL to deal with NULL values in a particular way?
For the following query, I want the result to be zero and not NULL if v1 or v2 is NULL:
SELECT t.v1 * t.v2
FROM table1 t;

For the following query, I want no spaces and not NULL to be concatenated if v2 is NULL:
SELECT CONCAT(t.v1," ",t.v2)
FROM table1 t;

View Replies !
Enter Null As Value
i have a dropdown box with the first box's value as "null" if they do not select it. However, when i enter the value into the db through query it returns it as 0. is there anway so it is null in the db?

View Replies !
Getting NULL For Results
SELECT DATEDIFF('date_hired,'date_fired') from users

and i get all NULL for results

i think i should be getting number of days apart from the two dates


date_hired and date_fired are both date columns

so whats wrong with this

View Replies !
If NULL, Get Value From Second Column
I used to do it many times in the past but now I completely forgot the syntax, so here I go:

What I want to do is select from one specific column, if this column is empty (NULL or = "") get the value from a second column instead. I remember doing it with a single query, but now I can't seem to remember or find how to do that.

View Replies !
How Can I See If A Field Has A Null Value?
How can I see if a field has a null value? I have a date field that has a default value of NULL.

if($getline[charged] IS NULL){
echo "Yes field is NULL"}

View Replies !
NULL Field Or NOT NULL Field?
I have created a DB and started using PHP to pull data and display it. However I am having trouble understanding the Null field.

I've searched the web and read what I could but I am no more intelligent from that research .Can someone put into simple words what this field means ? What happens when it is set to "null" or "not null".

View Replies !

Copyright © 2005-08 www.BigResource.com, All rights reserved