LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 12-07-2008, 05:04 AM   #1
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Rep: Reputation: 56
Question on MySQL


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 05:09 AM.
 
Old 12-07-2008, 06:34 AM   #2
niknah
Member
 
Registered: Dec 2002
Location: In front of a computer
Distribution: UPS, DHL, FedEx
Posts: 466

Rep: Reputation: 38
You can't make the primary key null cause then only one row would be allowed to be null(primary keys are unique)

Try this...

CREATE TABLE `tblPerdition` (
`user` varchar(128),
`servername` varchar(255) not null,
`port` varchar(8) NULL default 'NULL',
);
 
Old 12-07-2008, 06:49 AM   #3
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by niknah View Post
You can't make the primary key null cause then only one row would be allowed to be null(primary keys are unique)

Try this...

CREATE TABLE `tblPerdition` (
`user` varchar(128),
`servername` varchar(255) not null,
`port` varchar(8) NULL default 'NULL',
);
Hi niknah,


Thanks for your advice.


Tried unable to work for me;


Code:
mysql> CREATE TABLE `tblPerdition` (
     -> `user` varchar(128),
     -> `servername` varchar(255) not null,
     -> `port` varchar(8) NULL default 'NULL',
     -> PRIMARY KEY (`user`)
     -> );
Query OK, 0 rows affected (0.07 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.02 sec)

If putting on the 3rd line;
Code:
`servername` varchar(255) null '' default '',
It complained syntax incorrect.


Edit:

On Null field does it only have "NOT NULL" and "NULL"?


I'm following MySQL on following thread;
http://www.vergenet.net/linux/perdit...tiondb.5.shtml

to setup this table.


B.R.
satimis

Last edited by satimis; 12-07-2008 at 07:14 AM.
 
Old 12-07-2008, 05:52 PM   #4
niknah
Member
 
Registered: Dec 2002
Location: In front of a computer
Distribution: UPS, DHL, FedEx
Posts: 466

Rep: Reputation: 38
Quote:
If putting on the 3rd line;
Code:
`servername` varchar(255) null '' default '',
It complained syntax incorrect.
That was your line that you had put there?
I had removed the primary key too.



To make the perdition table use...

CREATE TABLE `tblPerdition` (
`user` varchar(128) primary key,
`servername` varchar(255) not null,
`port` varchar(8)
);
 
Old 12-07-2008, 06:49 PM   #5
satimis
Senior Member
 
Registered: Apr 2003
Posts: 3,695

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by niknah View Post
That was your line that you had put there?
I had removed the primary key too.

To make the perdition table use...

CREATE TABLE `tblPerdition` (
`user` varchar(128) primary key,
`servername` varchar(255) not null,
`port` varchar(8)
);
Hi niknah,

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 got it. Thanks.


The table on that URL gave me a wrong concept looking for solution to make "Null" blank.


B.R.
satimis
 
  


Reply



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. SpellChainz Linux - Newbie 1 06-23-2007 03:35 PM
mysql error Can't connect to local MySQL server through socket '/var/lib/mysql/mysql. Dannux Linux - Software 3 03-24-2006 08:44 AM
MySQL question jayakrishnan Linux - General 5 03-24-2003 10:59 PM
MySQL question ascii2k Linux - General 1 03-27-2002 04:48 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 12:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration