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 Complete Forum Thread with Replies
Related Forum Messages:
NULL Default Value
I have a simple table. I'm using phpmyadmin. As you can see my default values for NULL are 0 but for some reason wen a null value is posted to the database it appears as "NULL" instead of "0"....
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 !
User Name Null And Socket Default
I installed mysql 4.1.11 in a linux workstation and started it new. I have 2 problems 1. socket defaults to /tmp/mysql.sock. <- How will I change the default socket to another directory where it actually resides. 2. When I enter in mysql, and do something the user name is forgotten and hence I get this error message. (I tried with both --user option and without it.) Access denied for user ''@'localhost' to database 'mysql' When I work as a root user there is no problem.
View Replies !
Error #1064 Near 'COLLATE Latin1_general_ci NOT NULL Default ''
I try to restore my wordpress (it's a php-based blog system) database on my remote webserver running MySQL 4.0.24. When I try to pass this SQL statement: CREATE TABLE `wp_categories` ( `cat_ID` bigint( 20 ) NOT NULL AUTO_INCREMENT , `cat_name` varchar( 55 ) COLLATE latin1_general_ci NOT NULL default '', `category_nicename` varchar( 200 ) COLLATE latin1_general_ci NOT NULL default '', `category_description` longtext COLLATE latin1_general_ci NOT NULL , `category_parent` int( 4 ) NOT NULL default '0', PRIMARY KEY ( `cat_ID` ) , KEY `category_nicename` ( `category_nicename` ) ) ENGINE = MYISAM DEFAULT CHARSET = latin1 COLLATE = latin1_general_ci AUTO_INCREMENT =9 I got this error: MySQL said: #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 'COLLATE latin1_general_ci NOT NULL default '', `category_nicen I tried to replace ` with ' but this didn't work either. My local server is running on MySQL 4.1.15 without problems.
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 !
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 !
Specifying Default ''
does specifying default make the table smaller, like setting_title varchar(32) NOT NULL default '', instead of setting_title varchar(32) NOT NULL, make the entire row smaller, instead of a blank 32?
View Replies !
Bad? Id Int(11) DEFAULT '0'
I'm trying to install the authlib module that's required for the open-source iOutliner web-based outliner (http://ioutliner.com), but it fails halfway through when creating the tables: //Bad! /* SQL Error: Invalid default value for 'id' */ $query = mysql_query("CREATE TABLE authlib_data ( id int(11) DEFAULT '0' NOT NULL auto_increment, name text NOT NULL, email text NOT NULL, age int(3) DEFAULT '0' NOT NULL, sex text NOT NULL, school text NOT NULL, PRIMARY KEY (id) )"); //Bad! /* SQL Error: Invalid default value for 'id' */ $query = mysql_query("CREATE TABLE authlib_login ( id int(11) DEFAULT '0' NOT NULL auto_increment, username text NOT NULL, password text NOT NULL, PRIMARY KEY (id) )"); According to Google, DEFAULT '(0)' seems a legit instruction. What's wrong with this?
View Replies !
Default Date??
I have a field (called active) of type DATE and I want to add a default value. The default value must be the current date. Is this possible to do this in the table create statement? CREATE TABLE mytable ( id INTEGER NOT NULL AUTO_INCREMENT, active DATE DEFAULT ?????, PRIMARY KEY (id), )
View Replies !
Default Permissions
This is a fairly simple question but I'm new to mySQL. To log on to mySQL I need to type at the prompt: mysql --user='username' --password='password' as opposed to just typing mysql and being recognized without having to type identification. Anyone know how I can change this?
View Replies !
Timestamp Default Value
I am using: mysql Ver 12.22 Distrib 4.0.18, for sun-solaris2.9 (sparc) And I do this: mysql> create table test (a timestamp default null, b timestamp default null); Query OK, 0 rows affected (0.03 sec) mysql> desc test; +-------+---------------+------+-----+----------------+-------+ | Field | Type | Null | Key | Default | Extra | +-------+---------------+------+-----+----------------+-------+ | a | timestamp(14) | YES | | NULL | | | b | timestamp(14) | YES | | 00000000000000 | | +-------+---------------+------+-----+----------------+-------+ 2 rows in set (0.00 sec) Can anyone tell my why the default value for column 'b' is not NULL as well?
View Replies !
Changing A Default Value
i have a column that originally assigned a default integer value (1) to a column that contains about 1000 records. now, i'd like to replace all those with an incremented value. i figured out how to change it so newly added data is incremented, but cant seem to figure out the command to go back and change all data from the beginning so that it is now incremented.
View Replies !
MySQL Default Value
When a customer places an order, the database sets the default at "3" which means "not complete" when it is complete and billed, It is assigned a "1" I want to have it be assigned a new number on all future orders, but no not want it to go back and reset every single past order. If I change the default value number in the database, will it only apply to new orders, or will it change every single record to the new default regardless of their current status?
View Replies !
Set Default Collation
However I recently tried MySQL 4.1.x and noticed that there have been some changes. My questions are:- 1) The default collation setting is Latin1_swedish_ci. What do I need to change this to in order for my old tables to import correctly? Currently special chars like tm <- trademark import as ? <-Question Marks? 2) How do I set my own default? 3) Is there any way to export a new database back to an old version of MySQL eg 4.1.x -> 4.0.x?
View Replies !
Default Character Set
I have a problem with character set client and connection. I have all tables in cp1250_czech_cs collation and I have set a global session character_set_client, character_set_connection and character_set_result to cp1250. When I make a connection to the database in PHP (mysqli_connect()) and execute a query SHOW SESSION VARIABLES; it return that character_set_client, character_set_connection and character_set_client is set to latin1. What can I do, when I want to set this variables to cp1250 as default? (and not use SET NAMES cp1250; in each script).
View Replies !
[Default] Order
I have a MySQL database with a table that I assumed "by default" would insert records in chronological order - i.e. just add each record to the end of the table. What is happening however is that 'some' records are inserted just somewhere in the file - not at the end of the table. I can tell this because there is a date field in the table. How do records get added to a database? by key, index, ???? Is there some way to force a record to be added to the bottom of the table? Key info about the table: . there is not a primary key. . there are 3 index's
View Replies !
Field Default Value
This may have already been asked. But I couldn't find anything. (Maybe I am asking the wrong question).How do I find out the default value of a field using php? Something similar to mysql_field_name() or something.
View Replies !
Overriding Default
Can I change the default minimum length of words in Fulltext Search without having to ask my web hosting company to do it? I mean, change the value using through PHP script?
View Replies !
Timestampt Default
When I create a timestamp field in phpmyadmin it's default is always 000-00-00 00:00:00 instead of just a number. Anyone know why and how to change this? I tried deleting the default but when I hit save it puts it back in.
View Replies !
Default Field
There is a table, with some fields including an auto_increment field, some more integer type, text,varchar etc type of fields. 2. I am trying "SELECT * FROM myTable" [No ORDER BY clause used] question: Which field will be used by default, for ordering the records? Will it be the primary key(which is auto_increment) always?
View Replies !
Default Autocommit=0?
Is there any way I can set up mysql client so that the default value for autocommit is 0? This is for when I'm running the command line client on linux/windows or the Query Browser on windows. I would feel much more comfortable that I'm not going to accidentally put in the wrong where clause and update or delete a bunch of records. I like to use the number of rows affected by my query as a double-check that I've done what I intended to do, and then commit it. I've searched around but could not find any mention of this issue -- all of the postings on autocommit that I found have to do with accessing mysqlserver from a program such as java or PHP.
View Replies !
DEFAULT DATE
I need a sistem variable for get the actual date when I create a table. I use sysdate in Oracle and it works, but i have not idea about mysql. I want to use into a create table like this: CREATE TABLE users( id_user int PRIMARY KEY, registrationday date DEFAULT sysdate );
View Replies !
How Set Default To CURRENT_TIMESTAMP?
I have a column of type datetime which I would like to have a default value of CURRENT_TIMESTAMP. I have tried: ALTER TABLE table1 ALTER dateEntered SET DEFAULT CURRENT_TIMESTAMP but this gives a syntax error, probably because it wants a literal at the end there.
View Replies !
Default Value For Date
CREATE TABLE ... `birthdate` DATE DEFAULT CURRENT_DATE(), ... doesn't work - produces syntax error. Anybody know how to declare current date as the default value for a DATE column?
View Replies !
DATE DEFAULT ...
If I want to use date for my column and I want to set a default for it what do I specify? I know for timestamp I can use current_timestamp but what do I use for date?
View Replies !
DATETIME - Set Default Value
I have a database table (MYSQL v5.0.67) in which I store several date fields. I have set these all to be not null and to have a default value of '0000-00-00 00:00:00' e.g. `last_login` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', However when I run my create database script (generated from a schema design in MYSQL Workbench) it complains as follows: Error Code : 1067 Invalid default value for 'last_login' I leave it as nullable with no default value and run the script to create the table which works fine. I can then use a tool like SQLyog to alter the table generated and set this to be not null with a default of 0000-00-00 00:00:00 and it is happy to alter the table. Obviously this is not ideal and it should work straight from the script.
View Replies !
What Is Default Database Name
I want to specify access options for MySQL. Please tell what is MySQL hostname, MySQL username, MySQL passoward & MySQL database name for the connection to the MySQL server.
View Replies !
Select Default Value
two tables: master_table ( id int not null, work_id int not null, sub_work_id int not null, primary key(id) ) ref_table ( id int not null, work_id int not null, sub_work_id int null, name varchar(20), primary key(id) )
View Replies !
Use Now() As Default Value For A Column
I cannot find any good material on this, and it seems like it should be so easy. I have two columns in my table, creation_date and last_modified_date. I want the creation_date field to bear the default value of Now(), so that when a row is created the timestamp is there. This value should never change, and should only be set on row creation. The last_modified_date field I want to change on the UPDATE only. It seems that this may be possible using the TIMESTAMP type and the default values there but what I read is that they will update everytime a row is altered. This would be dead-simple if I could just specify Now() as the default value.
View Replies !
How Do I Set A Default Date Value
I have tried putting in now() via phpmyadmin as the default value and my new record entries return a value of '0000-00-00'. My purpose is to have a default created_date of the time mySql writes each new row.
View Replies !
Default Delimiter Not Set
No query specified. The only way to end it was CTRL+C. Using g and G work normally, and if I manually type "DELIMITER ;", then I can use the semicolon just fine (until I log out and back in again.) Is there some configure option I need to use to make sure the semicolon is the default delimiter?
View Replies !
Default Block_size
I would like to ask what would be the default block_size in mysql 5.1.33. Just like in oracle, the block_size may vary or depend on the OS block_size. Is the block_size in mysql same with each storage engines.
View Replies !
NOT NULLs With Default
I'm cleaning up a database but I see this all over the MySQL world. I understand that having defaults speeds things up. But what I don't understand is why someone would make a field NOT NULL and then put a null default in it? This makes no sense to me at all. Is this the fault of using phpMyAdmin to create tables? Here's a sample: CREATE TABLE `listnames` ( `id` int(11) NOT NULL auto_increment, `list_name` char(30) NOT NULL default '', `display_name` char(100) NOT NULL default '', `active` char(3) NOT NULL default '', `last_modified` timestamp(14) NOT NULL, UNIQUE KEY `id` (`id`) ) Ok, so you don't want NULLs in your data but there is no default. It's very likely that the data will be wildly differently. So setting a default makes no sense -- or does it? I don't want to drop the default '' if it makes sense & I'm just not getting it.
View Replies !
Default Value For A Column, When Value Is Not Specified
We have migrated our database from DB2 to MYSQL. In DB2, there is an option like 'GENERATED BY DEFAULT AS IDENTITY' which will cause DB2 to generate unique values for the identity column during insert operations if no value is specified for the identity column. However, if a value is specified for the identity column, DB2 will use it in the insert operation. In MYSQL, is there an option like this?
View Replies !
Default Value On A Column
Hey guys, my hope is to quickly move from SQL2005 to mySQL and i'm hitting the GUID roadblock. If mySQL can't do a GUID by default on a column, I've got to rewrite a ton of my application around that. Tell me with 5.0 this is possible now? Or that there's some cool work-around?
View Replies !
DATETIME DEFAULT Now().
I would like to know in what way, I can set the default value of a DATETIME field to Now() so I don't need to put the code in my scripts. ALTER TABLE `tbltest` CHANGE `TheDate` `TheDate` DATETIME DEFAULT 'Now()' With the ' ' it doesn't error, but it's probibly just sending the string "Now()" and I get the default date 0000-00-00. If I take off the ' ' I get an error. Anyone know a way I can set my default value for my DATETIME field to automatically insert the date and time with each new record?
View Replies !
Default For The Type SET
I've created a database with a field of the type SET. Something like this: SET('choice1','choice2','choice3'). The default choice is the empty ('') string. Do I have to also define the empty string in the set like this SET('choice1','choice2','choice3','') or is this not necessary?
View Replies !
|