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.





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 Complete Forum Thread with Replies

Related Forum Messages:
Setting Date 0000-00-00 As NULL?
I'm working on little webapp where one field is set to MySQL DATE datatype. by default this will go to 0000-00-00 which is fine, so I'm wondering if it's possible to have a query that see if the value is the "0000-00-00" and return NULL.

select this, that, date FROM table .. if date = '0000-00-00' set date NULL ...

or something?

View Replies !
Setting Cols To NULL By Default
For a developer who's making MySQL tables strictly for website content, and who is very confident that his PHP site will unerrorneously integrate with that database: should he make his columns NULL by default or no?Currently the code overlooks empty sets, cells, etc. where necessary; like I said, unerroneous.Right now it's just an issue of being technically correct, if you will. Never cared to set default values.NULL or NOT NULL ?

View Replies !
Query Browser: Setting NULL Values
with a Query Browser resultset in Edit mode, how can the NULL value be set? If the word NULL is entered, it is interpreted as the string 'NULL'.

View Replies !
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 !
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 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 !
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 !
NULL Values
I have 2 tables, one for links and other for categories.
each link might be associated with some category BUT not necessarily.
table 'category' has 'id' field with auto increment.
table 'link' has field 'CategoryId' which points to some category id.

In case some link is not associated with any category what value for 'categoryId' is more suitable: NULL or -1?

View Replies !
Optimize - NULL V.s. 0 Or ''
To optimize a fairly large table with variable length fields, is it generally better to use a default value of NULL or an empty string?

ex: for char types, use NULL in stead of ''
or for numeric types, use NULL in stead of 0

if there was a notable advantage/disadvantage to a lot of NULL values in a large table, and if so whether it is due to disk storage requirements or processing time/overhead?

View Replies !
Null Value Is Eliminated
Hey all. I am getting this warning when I execute my query. It is still populating the results correctly, its just giving me this warning and I dont know how to get rid of it. I know one of my solutions is:
SET ANSI_WARNINGS OFF

-- sql code

SET ANSI_WARNINGS ON

but I want to know why that is happening. It seems to be caused by the MAX function in the following line:

DECLARE @BusinessDay DATETIME
DECLARE @PreviousBusinessDay DATETIME
SELECT @BusinessDay = (SELECT MAX(PeriodDate) FROM TableName)
SELECT @PreviousBusinessDay = DATEADD(dd,-1,@BusinessDay) FROM TableName.

View Replies !
Null Columns
If I set a column to be null, does that mean that it's null by default? If so, will this save an assload of space?

View Replies !
Replace NULL
I searched six pages of NULL information, and learned a lot about NULL conditions in MySQL, but it didn't help me figure out my own desire.

I'm performing a very simple query:

SELECT * FROM MONSTER;

The table returns with over 200 columns. Some values may be NULL. Is there an easy way to replace "NULL" with a string value, such as "NOTHING"?
It sure would be sweet if there is!

Upon Googling it, it looks like MSSQL has an "ISNULL(field, "replacewith") function. Just wondering if there's a way to do it within a MySQL query.

View Replies !
Select Null
Basically I have a db with join_ip's I want to set all account to 0 (zero) if they don't have an IP.
What I come up was this:

UPDATE nn_users SET active = 0 WHERE join_ip = '';

But it doesn't work, I've even tried doing join_ip = null; that didn't work as well.

View Replies !
Select With Not Null
Why is it with the query below I still get the rows that have null as a value for make? I checked with MySQL Admin and the make has the null indicator as a default value.Code:

SELECT * FROM my.data g where make IS NOT NULL;

After looking at this iin query browser I see that some of my rows show null and other rows does not show the null image yet have no data.
so like this..

ID | make
1 null
2
3 null

All the above should be null

View Replies !
Sum And Null Values
Was reading another recent post (select daily item orders & totals for a given month ), and not to write on the same post I open an new one, reading it made me remember an small problem I experienced using below (part) of code.

sum(importe)
- sum(servicios)
-sum(pagado) as total_duenos

Sometimes when adding a new property and when I sum , the column importe has values but the others two do not have anything yet, and I get as result 0, which is not correct, so to fix it, I put 0.00 in the columns servicios and pagado.
the columns in question are type:decimal(10,2)
Is this due to that the columns have as default value null?
The null and not null is something I ever understood.

View Replies !
Using And Inserting NULL
Is it possible to insert NULLs when making an INSERT statement where the column counts dont match to have the extra columns be inserted with NULLs automatically?
The following is my query

insert into team select playerID,teamID from batting where playerID like 'aaro%' group by teamID

aaron played for 3 teams, but the table team has space for 7 teams. I would like team4..team7 to get NULLs, if possible or another way to not get the column count doesn't match error.

View Replies !
Inside IF NULL
I have this table:
------------------
id lang name
1 en name1
1 de NULL
2 en name2
2 de name3

I want to return all (WHERE lang='de') rows but if the (name=NULL) then replace it with name from the same id but lang='en'. Is it possible?

I have this query:

SELECT IFNULL(name, SELECT name FROM table WHERE lang='en' AND id=????) name FROM table WHERE lang='de'

Can you fix it?

View Replies !

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