Go Back   CodingForums.com > :: Server side development > MySQL

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-28-2007, 09:04 AM   PM User | #1
amieAp
New to the CF scene

 
Join Date: Aug 2006
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
amieAp is an unknown quantity at this point
mysql primary key

A primary key in ORACLE implies unique and not null, implies u cannot leave the column empty during an insert. In mysql, a column defined as a primary key accepts if nothing is inserting into that column during an insert, for the first time. The next time the same is performed(ie., leaving the primary key column empty), it is violation of primary key constraint.
That is, mysql's definition of primary key implies only unique but not NOT NULL. Wat do i do to have a column both unique and notnull?
amieAp is offline   Reply With Quote
Old 02-28-2007, 02:16 PM   PM User | #2
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
When you leave it out an empty string is entered. That is not the same thing at all as NULL. so even if you declared it as a NOT NULL column, you can still leave it empty on the first insertion.
guelphdad is offline   Reply With Quote
Old 03-05-2007, 09:30 PM   PM User | #3
FJbrian
Regular Coder

 
Join Date: Jun 2002
Location: Adirondacks
Posts: 516
Thanks: 4
Thanked 4 Times in 4 Posts
FJbrian is on a distinguished road
when I create a table in phpmyadmin I'd swear one of the choices in the pull down menu is "not null"
Maybe I'm thinking of something else
__________________
FootballHangout.com
FJbrian is offline   Reply With Quote
Old 03-05-2007, 11:42 PM   PM User | #4
guelphdad
Super Moderator


 
guelphdad's Avatar
 
Join Date: Mar 2006
Location: St. Catharines, Ontario Canada
Posts: 2,629
Thanks: 4
Thanked 147 Times in 138 Posts
guelphdad will become famous soon enoughguelphdad will become famous soon enough
there is a choice of NOT NULL because you can make a column NOT NULL. and you can create the column as UNIQUE.

An empty string can still be entered in the table once because an empty string isn't NULL. On the second insertion of an empty string though you won't be able to do it because an empty string exists.
guelphdad is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 09:47 PM.


Advertisement
Log in to turn off these ads.