Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
Old 12-07-2008, 06:58 AM About MySQL command
Average Talker

Posts: 27
Trades: 0
Hi folks,


mysql version
Ver 14.12 Distrib 5.0.32


I ran following command creating a table:-


Code:
mysql> CREATE TABLE `tblPerdition` (
     -> `user` varchar(128),
     -> `servername` varchar(255) default '',
     -> `port` varchar(8) NULL default 'NULL', 
    -> PRIMARY KEY (`user`) 
    -> ); 
Query OK, 0 rows affected (0.00 sec)
Code:
mysql> DESCRIBE tblPerdition;
+------------+--------------+------+-----+---------+-------+
| Field      | Type         | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| user       | varchar(128) | NO   | PRI |         |       |
| servername | varchar(255) | YES  |     |         |       |
| port       | varchar(8)   | YES  |     | NULL    |       |
+------------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
I can't figure out how to made Null columns of 'user' blank (without NO)
and 'servername' blank (without YES)


Please help. TIA


B.R.
satimis

Last edited by satimis; 12-07-2008 at 07:12 AM..
satimis is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 12-07-2008, 07:50 AM Re: About MySQL command
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
user is a primary key so cannot allow NULL entries

NOT NULL is the parameter to NOT allow NULL fields
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-07-2008, 08:53 AM Re: About MySQL command
Average Talker

Posts: 27
Trades: 0
Quote:
Originally Posted by chrishirst View Post
user is a primary key so cannot allow NULL entries

NOT NULL is the parameter to NOT allow NULL fields
Hi chrishirst,


Thanks for your advice.


Is "NO" on the Null field similar to blank?


Edit:

I was following this thread re MySQL;
http://www.vergenet.net/linux/perdit...tiondb.5.shtml

to set up this table.


B.R.
satimis

Last edited by satimis; 12-07-2008 at 09:18 AM..
satimis is offline
Reply With Quote
View Public Profile
 
Old 12-07-2008, 12:15 PM Re: About MySQL command
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
A "NO" in the NULL descriptor column means that the entry for that column in any row MUST HAVE A VALUE it is not allowed to be NULL.
A "YES" in the column indicates that is can be NULL

and no, NULL is not similar to blank, as blank may mean that the column contains a zero length string (""). NULL is nothing.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-07-2008, 09:00 PM Re: About MySQL command
Average Talker

Posts: 27
Trades: 0
Quote:
Originally Posted by chrishirst View Post
A "NO" in the NULL descriptor column means that the entry for that column in any row MUST HAVE A VALUE it is not allowed to be NULL.
A "YES" in the column indicates that is can be NULL

and no, NULL is not similar to blank, as blank may mean that the column contains a zero length string (""). NULL is nothing.
Hi chrishirst,


Please advise how to make "Null" blank. Thanks


Tried follow without success;

Code:
mysql> CREATE TABLE `tblPerdition` ( 
     -> `user` varchar(128) null '' primary key,
     -> `servername` varchar(255) null '',
     -> `port` varchar(8)     -> );
ERROR 1064 (42000): 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 ''' primary key,
`servername` varchar(255) null '',
`port` varchar(8)
)' at line 2
B.R.
satimis
satimis is offline
Reply With Quote
View Public Profile
 
Old 12-08-2008, 04:02 AM Re: About MySQL command
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Code:
`user` varchar(128) null '' primary key,
1/ You cannot allow NULL entries in a primary key

from http://dev.mysql.com/doc/refman/5.0/...ate-table.html
Quote:
A PRIMARY KEY is a unique index where all key columns must be defined as NOT NULL. If they are not explicitly declared as NOT NULL, MySQL declares them so implicitly (and silently). A table can have only one PRIMARY KEY. If you do not have a PRIMARY KEY and an application asks for the PRIMARY KEY in your tables, MySQL returns the first UNIQUE index that has no NULL columns as the PRIMARY KEY.
Quote:
Please advise how to make "Null" blank. Thanks
You can't, NULL is not blank.
NULL is a special case and is the absence of anything

the error is caused by your code missing out the DEFAULT column descriptor
Code:
servername` varchar(255) null DEFAULT '',
Including the "NULL" when creating the table is not necessary. Unless you specify "NOT NULL", the column will allow NULL entries on non key fields.
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-08-2008, 09:07 AM Re: About MySQL command
Average Talker

Posts: 27
Trades: 0
Quote:
Originally Posted by chrishirst View Post
Code:
`user` varchar(128) null '' primary key,
1/ You cannot allow NULL entries in a primary key

from http://dev.mysql.com/doc/refman/5.0/...ate-table.html


You can't, NULL is not blank.
NULL is a special case and is the absence of anything

the error is caused by your code missing out the DEFAULT column descriptor
Code:
servername` varchar(255) null DEFAULT '',
Including the "NULL" when creating the table is not necessary. Unless you specify "NOT NULL", the column will allow NULL entries on non key fields.
Hi crishirst,


Thanks for your advice.


Re-run following command;

Code:
mysql> CREATE TABLE `tblPerdition` (
     -> `user` varchar(128) primary key,
     -> `servername` varchar(255) not null,
     -> `port` varchar(8)
     -> ); Query OK, 0 rows affected (0.00 sec)
Code:
mysql> DESCRIBE tblPerdition;
+------------+--------------+------+-----+---------+-------+
| Field      | Type         | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| user       | varchar(128) | NO   | PRI |         |       |
| servername | varchar(255) | NO   |     |         |       |
| port       | varchar(8)   | YES  |     | NULL    |       |
+------------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
I suppose I can't make "Null' blank?


B.R.
satimis
satimis is offline
Reply With Quote
View Public Profile
 
Old 12-09-2008, 06:52 AM Re: About MySQL command
chrishirst's Avatar
Missing! presumed drunk.

Posts: 41,517
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I suppose I can't make "Null' blank?
IF you mean the column descriptor (as shown by "DESCRIBE table") No you can't, it will be "YES" or "NO"
__________________
Chris. ->> Links are advertising NOT optimising!! <<-
A foolish consistency is the hobgoblin of little minds
Thought for today:- I SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 12-09-2008, 09:32 AM Re: About MySQL command
Average Talker

Posts: 27
Trades: 0
Quote:
Originally Posted by chrishirst View Post
IF you mean the column descriptor (as shown by "DESCRIBE table") No you can't, it will be "YES" or "NO"
Noted with thanks


satimis
satimis is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to About MySQL command
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28674 seconds with 12 queries