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.





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

Related Forum Messages:
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 !
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 !
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 !
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 !
Checking A Field For NULL
I have imported information into a database using a file. It is tab
delimited and for NULL fields I have NULL.

example file.txt
1<tab>Hello World<tab>NULL<tab>5.56

1) Is this a correct way to make sure that this field will be NULL

2) in C++ after I fetch the field can I say
if(<field> != NULL)

View Replies !
NULL For Date Field
I have a date field in my database which is set to accept NULLs. If I enter a record from phpMyAdmin and leave the date field blank, the record is entered properly. However, if I do the same thing from a form, I get an error that the date cannot be blank. It seems that I need to enter a NULL in the date field from the form rather that nothing.

View Replies !
Date Field Null Value
I have a date field set as default="NULL". I think that is causing me problems when I try to see if that date field contains a value. The mysql below only works when I get rid of the date field AND charged='NULL'. How can I tell if a date contains a NULL value?

"SELECT *
FROM orders
WHERE enterdate >= '$fromsql'
AND enterdate <= '$tosql'
AND orderstatus='CLOSED'
AND charged='NULL'

View Replies !
Is It Possible To Do Math On A Null Field?
I have a result set that is composed of three columns.

ColumnA, ColumnB, ColumnC (ColumnC = ColumnA + ColumnB)
1________1_______2
1________2_______3
NULL____1_______NULL
1________NULL____NULL

ColumnC is a calculated field which is the sum of columns A and B. My dataset is such that sometimes columns A or B will not be populated with a number. Currently, when MySQL tries to add any value to NULL it returns NULL. Instead of this behavior, I would like to treat the NULL values as zeroes.

View Replies !
Null Field Values
I created a new database for an application that i am working on , from the delphi application that connects to mysql 5 database i can pass records with no data to not null fields , i was suprise and i did the same thin from mysql query browser, it seems that mysql dosn't check tha property before it stores the reccord.

View Replies !
Checking If Field Is NULL In C++
I have populated a table using a file.

example of file.txt (tab delimited)

1 Gary NULL 5.67
2 Chris 576-2435 NULL
3 Robin 234-7865 6.5
4 Matt NULL NULL

1)Is this a correct way to enter NULL for field values when importing from a file?

2)In c++, I do a query on the fourth field in row 1(SELECT fourthField FROM table where firstField = 1) and have it stored in a char** row. Can I say:

if(row[0] != NULL)
{
do something
}

to check if it is NULL. if not how do I check to see if this field value is NULL.

View Replies !
How To Query WHERE Field = NULL?
I've been digging for some while now (off and on) for the means by which to query for fields with value of NULL, but haven't turned anything up yet....

View Replies !
Returning Null Value From Field In DB
This is my code :

$sql = "SELECT * FROM albumrev WHERE bandname = '$bdname' AND albname = '$abname'";
$result = mysql_query($sql);

while ($row = mysql_fetch_array($result))

How to code when there's no data entered in the db, it'll just display No Data Entered Yet. Is it done using the Count() command ?

View Replies !
Selecting As 'something' If Field Is NULL
I'm doing the following QUERY:

"SELECT *, person.person_id as person_id, type.description as typename FROM person".
LEFT JOIN registration on person.person_id = registration.person_id AND registration.event_id = ".$event_id.
LEFT JOIN type on registration.type_id = type.type_id WHERE person.person_id != ''";


If there is no registration record linked, then it will return blank for the 'typename' but I want it to return 'default'? Is there a way I can have it do this?

View Replies !
Not Null Field Causing Issues
I have a C# application that calls a MySQL procedure and writes data to the db. All of the fields get populated properly but for the ID field, which is my PK field. It populates the field with an empty string instead of the value. the ID field is a varchar field.

When I try a direct insert through the MySql Query Browser, it populates the field correctly, but when using the C# code/appl. the above issue occurs.

View Replies !
Null Field Not Taking Data
I have a mysql table with a password field. (varchar(20), Null YES). When i input data into the field from the form, I look at the table and it say null. It's not taking the data that I input into it.

View Replies !
Select Field With NULL Data
check this out:
mysql> select price, price_increase from l_foods;
+-------+----------------+
| price | price_increase |
+-------+----------------+
| 2.64 | 0.25 |
| 1.94 | NULL |
| 4.67 | 0.40 |
| 7.94 | 0.70 |
| 3.35 | 0.30 |
| 1.32 | 0.05 |
| 1.94 | NULL |
| 1.68 | 0.25 |
| 1.15 | 0.15 |
| 3.97 | 0.50 |
+-------+----------------+
10 rows in set (0.01 sec)

I am tryingto select price for food item that does not have price_increase.
i tried something like
select price_description from l_food where price_increase = NULL;

but it gives me empty set.
what do i put for price_increase if it is null?

View Replies !
How To Check If Field Is Empty Or Null?
I have a problem. I store some avatar images in a database. And these avatars are optional for each user.

A general unknown avatar image is shown if the avatar field for the specified user is empty or null. Showing the avatar is a 2 step process.

First I want to check if the avatar field is not null. If it is not then retrieve the data and show it on the web page.

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 !
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 !
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 !

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