Re: [PHP-DB] Re: php-db foreign key

2011-08-10 Thread Karl DeSaulniers


On Aug 9, 2011, at 3:41 PM, Peter Lind wrote:

On 9 August 2011 22:38, Chris Stinemetz chrisstinem...@gmail.com  
wrote:


Yes, debug your code and figure out why it's looping twice instead.
For instance, try the other query in the mysql console.



Thank you! It was the first query. I put a LIMIT 1 on it and now it  
is

working correctly. I appreciate your help!



You're fixing the symptom, not the problem. Your query was returning
multiple values because something is wrong with the query or your
data. If you don't correct it, the problem will likely just grow
bigger.


--
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Hi Chris,
Is this what your looking for?

?php
//store.php
include_once 'includes/connect.php';
include_once 'includes/header.php';

//print(pre.print_r($_GET,true)./pre); //Not sure what this is  
for, uncomment if needed.


if(!$_SESSION['signed_in']) {//Check to see if signed in first, then  
do search, otherwise display and search nothing.

echo('table class=table1 border=1
tr
	td colspan=2You must be a href=signin.phpsigned in/a to  
reply. You can also a href=signup.phpsign up/a for an account./ 
td

/tr
/table');
}
else {
	$sql = SELECT * FROM stores WHERE store_subject =  
'.mysql_real_escape_string($_GET['id']).';

$result = mysql_query($sql);
//fetch the posts from the database
$posts_sql = SELECT
stores.store_subject,
stores.store_comments,
stores.store_date,
stores.store_tptest,
stores.store_by,
users.user_id,
users.user_name,
users.first_name,
users.last_name
FROM
stores
LEFT JOIN
users
ON
stores.store_by = users.user_id
WHERE
stores.store_subject = '.mysql_real_escape_string($_GET['id']).'
ORDER BY
stores.store_date
	DESC LIMIT=30;// Set a number of records if you dont want to display  
ALL records on one page and want to build in pagination.


if(!$result || mysql_num_rows($result) == 0) {
echo('This store visit doesnprime;t exist.');
}
else {
echo('table class=table1 border=1');
while($row = mysql_fetch_array($result)) {
//display post data
			$posts_result = mysql_query($posts_sql);//This may be the culprit  
you had. Do you mean to do the $posts_sql query for ever result in  
$sql query?? If not, move out of while loop above. Also, can you get  
the same result by just using the $posts_sql query and axe the $sql  
query?? They look like you get the same results to me. May be redundant.

echo('trtd 
colspan=2'.$row['store_subject'].'/td/tr');
if(!$posts_result || mysql_num_rows($posts_result) == 
0) {
echo ('trtdNo Post results./td/tr/table');
} else {
while($posts_row = 
mysql_fetch_array($posts_result)) {
echo('tr class=topic-post
	td class=user-post'.$posts_row['first_name'].'$nbsp;'. 
$posts_row['last_name'].'br/'.date('m-d-Y h:iA',  
strtotime($posts_row['store_date'])).'/td

/tr
	trtd class=post-content'.$posts_row['store_tptest'].'br/ 
'.htmlentities(stripslashes($posts_row['store_comments'])).'/td

/tr');
}
}

//show reply box
echo('trtd colspan=2h2Reply:/h2br /
form method=post 
action=reply.php?id='.$row['store_id'].'
textarea name=reply-content/textareabr /br /
input type=submit value=Submit reply /
/form/td/tr');
//finish the table
echo('/table');
}
}
}
include_once 'includes/footer.php';
?

HTH,

Karl DeSaulniers
Design Drumm
http://designdrumm.com


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] foreign key

2011-08-09 Thread Chris Stinemetz
Okay. I am pretty new to mysql so this may seem like a ridiculous
question to some people.

I am trying to use a LEFT JOIN query, but the results I am finding
unusual. For every record occurrence there is for the query, the
results are duplicated by that amount.

So if there are 3 records from the query results, then the output is 3
times what I expect.. if that makes sense.

From what I have researched so far. I believe I may need to add a
foreign key to build the relations between the two tables.

Based on the query can any tell me the correct way of adding the
foreign key if ,in fact, that is what I need?

I can provide table structures and information if necessary.

The query is:

$posts_sql = SELECT
store_subject,
store_comments, 
store_date,
store_tptest,   
store_by,
users.user_id,
users.user_name,
users.first_name,
users.last_name
FROM
stores
LEFT JOIN
users
ON
stores.store_by = users.user_id
WHERE
stores.store_subject = ' . mysql_real_escape_string($_GET['id']).'
ORDER BY
stores.store_date DESC ;

The query dump is:

SELECT store_subject, store_comments, store_date, store_tptest,
store_by, users.user_id, users.user_name, users.first_name,
users.last_name FROM stores LEFT JOIN users ON stores.store_by =
users.user_id WHERE stores.store_subject = 'Noland Park Plaza 3509 S.
Noland Rd' ORDER BY stores.store_date DESC

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] foreign key

2011-08-09 Thread Peter Lind
On 9 August 2011 20:31, Chris Stinemetz chrisstinem...@gmail.com wrote:
 Okay. I am pretty new to mysql so this may seem like a ridiculous
 question to some people.

 I am trying to use a LEFT JOIN query, but the results I am finding
 unusual. For every record occurrence there is for the query, the
 results are duplicated by that amount.

 So if there are 3 records from the query results, then the output is 3
 times what I expect.. if that makes sense.

 From what I have researched so far. I believe I may need to add a
 foreign key to build the relations between the two tables.

 Based on the query can any tell me the correct way of adding the
 foreign key if ,in fact, that is what I need?

 I can provide table structures and information if necessary.

 The query is:

 $posts_sql = SELECT
 store_subject,
 store_comments,
 store_date,
 store_tptest,
 store_by,
 users.user_id,
 users.user_name,
 users.first_name,
 users.last_name
 FROM
 stores
 LEFT JOIN
 users
 ON
 stores.store_by = users.user_id
 WHERE
 stores.store_subject = ' . mysql_real_escape_string($_GET['id']).'
 ORDER BY
 stores.store_date DESC ;

 The query dump is:

 SELECT store_subject, store_comments, store_date, store_tptest,
 store_by, users.user_id, users.user_name, users.first_name,
 users.last_name FROM stores LEFT JOIN users ON stores.store_by =
 users.user_id WHERE stores.store_subject = 'Noland Park Plaza 3509 S.
 Noland Rd' ORDER BY stores.store_date DESC


Is users.user_id unique?

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] foreign key

2011-08-09 Thread Chris Stinemetz

 Is users.user_id unique?


yes it is.

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] foreign key

2011-08-09 Thread Peter Lind
On 9 August 2011 20:49, Chris Stinemetz chrisstinem...@gmail.com wrote:

 Is users.user_id unique?


 yes it is.


What does your result look like? Hard to say what the problem is
without seeing the result.


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] foreign key

2011-08-09 Thread Chris Stinemetz


 What does your result look like? Hard to say what the problem is
 without seeing the result.


I am echoing the query and printing the get array just for debugging
purposes, but below you can see how it is repeating its' self.

Thank you



Array
(
[id] = Bella Roe 4980 Roe Blvd
)

Bella Roe 4980 Roe BlvdSELECT stores.store_subject, stores.store_comments,
stores.store_date, stores.store_tptest, stores.store_by, users.user_id,
users.user_name, users.first_name, users.last_name FROM stores LEFT JOIN
users ON stores.store_by = users.user_id WHERE stores.store_subject = 'Bella
Roe 4980 Roe Blvd' ORDER BY stores.store_date DESC Chris Stinemetz
08-09-2011 02:08PM600kbps-3.8mbps
testChris Stinemetz
08-09-2011 02:07PM0-250kbps
test1Reply:


Bella Roe 4980 Roe BlvdSELECT stores.store_subject, stores.store_comments,
stores.store_date, stores.store_tptest, stores.store_by, users.user_id,
users.user_name, users.first_name, users.last_name FROM stores LEFT JOIN
users ON stores.store_by = users.user_id WHERE stores.store_subject = 'Bella
Roe 4980 Roe Blvd' ORDER BY stores.store_date DESC Chris Stinemetz
08-09-2011 02:08PM600kbps-3.8mbps
testChris Stinemetz
08-09-2011 02:07PM0-250kbps
test1Reply:


Re: [PHP-DB] foreign key

2011-08-09 Thread Peter Lind
On 9 August 2011 21:23, Chris Stinemetz chrisstinem...@gmail.com wrote:


 
 
  What does your result look like? Hard to say what the problem is
  without seeing the result.
 

 I am echoing the query and printing the get array just for debugging 
 purposes, but below you can see how it is repeating its' self.

 Thank you

So you're saying that
SELECT stores.store_subject, stores.store_comments, stores.store_date,
stores.store_tptest, stores.store_by, users.user_id, users.user_name,
users.first_name, users.last_name FROM stores LEFT JOIN users ON
stores.store_by = users.user_id WHERE stores.store_subject = 'Bella
Roe 4980 Roe Blvd' ORDER BY stores.store_date DESC

returns

Chris Stinemetz 08-09-2011 02:08PM 600kbps-3.8mbps test
Chris Stinemetz 08-09-2011 02:08PM 600kbps-3.8mbps test
Chris Stinemetz 08-09-2011 02:07PM 0-250kbps test1
Chris Stinemetz 08-09-2011 02:07PM 0-250kbps test1

From the above, can't see where your problem is but something in your
join is obviously not unique - whether it's the first or second table.

--
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] foreign key

2011-08-09 Thread Chris Stinemetz
Okay. I just validated it is not in the left join query, but in my php. I
was able to build the correct relations.

Does anyone see any think in the php code below that may cause duplicate
table rows?

Thank you all.

?php
//store.php
include_once 'includes/connect.php';
include_once 'includes/header.php';
print(pre.print_r($_GET,true)./pre);
$sql = SELECT store_id, store_subject, store_comments, store_date,
store_tptest, store_by
 FROM stores
 WHERE store_subject = ' . mysql_real_escape_string($_GET['id']).';
$result = mysql_query($sql);
if(!$result)
{
 echo 'The latest post could not be displayed, please try again later.';
 //echo mysql_error(); //debugging purposes, uncomment when needed

}
else
{
 if(mysql_num_rows($result) == 0)
 {
  echo 'This store visit doesnprime;t exist.';
 }
 else
 {
  while($row = mysql_fetch_assoc($result))
  {
   //display post data
   echo 'table class=table1 border=1
 tr
  th colspan=2' . $row['store_subject'] . '/th
 /tr';

   //fetch the posts from the database
   $posts_sql = SELECT
  stores.store_subject,
  stores.store_comments,
  stores.store_date,
  stores.store_tptest,
  stores.store_by,
  users.user_id,
  users.user_name,
  users.first_name,
  users.last_name
 FROM
  stores
 LEFT JOIN
  users
 ON
  stores.store_by = users.user_id
 WHERE
  stores.store_subject = ' . mysql_real_escape_string($_GET['id']).'
 ORDER BY
  stores.store_date DESC ;

  //echo $posts_sql;

   $posts_result = mysql_query($posts_sql);

   if(!$posts_result)
   {
echo 'trtdThe posts could not be displayed, please try again
later./tr/td/table';
//echo mysql_error(); //debugging purposes, uncomment when needed
   }
   else
   {

while($posts_row = mysql_fetch_assoc($posts_result))
{
 echo 'tr class=topic-post
   td class=user-post' . $posts_row['first_name'] . ' ' .
$posts_row['last_name'] . 'br/' . date('m-d-Y h:iA',
strtotime($posts_row['store_date'])) . '/td
   td class=post-content' . $posts_row['store_tptest'] . 'br/' .
htmlentities(stripslashes($posts_row['store_comments'])) . '/td
/tr';
}
   }

   if(!$_SESSION['signed_in'])
   {
echo 'trtd colspan=2You must be a href=signin.phpsigned in/a
to reply. You can also a href=signup.phpsign up/a for an account.';
   }
   else
   {
//show reply box
echo 'trtd colspan=2h2Reply:/h2br /
 form method=post action=reply.php?id=' . $row['store_id'] . '
  textarea name=reply-content/textareabr /br /
  input type=submit value=Submit reply /
 /form/td/tr';
   }

   //finish the table
   echo '/table';
  }
 }
}
include_once 'includes/footer.php';
?


[PHP-DB] Re: php-db foreign key

2011-08-09 Thread Frank Flynn
You already have a foreign key, that is stores.store_by references 
users.user_id.  You might not have declared it (which is OK) but if that is the 
key you want that is fine.

I suspect you are seeing an inadvertent Cartesian product.  The way you have 
written this query you will get one row from the stores table for each row in 
the users table where a store_by = user_id - and because you said LEFT JOIN 
you will get one row from the stores table even if there are no matching rows 
in the users table.

So you say you get 3 x the rows you're expecting; are there 3 users that match 
that store_by?

Good Luck,
Frank

On Aug 9, 2011, at 11:31 AM, php-db-digest-h...@lists.php.net wrote:

 From: Chris Stinemetz chrisstinem...@gmail.com
 Subject: foreign key
 Date: August 9, 2011 11:31:51 AM PDT
 To: php-db@lists.php.net
 
 
 Okay. I am pretty new to mysql so this may seem like a ridiculous
 question to some people.
 
 I am trying to use a LEFT JOIN query, but the results I am finding
 unusual. For every record occurrence there is for the query, the
 results are duplicated by that amount.
 
 So if there are 3 records from the query results, then the output is 3
 times what I expect.. if that makes sense.
 
 From what I have researched so far. I believe I may need to add a
 foreign key to build the relations between the two tables.
 
 Based on the query can any tell me the correct way of adding the
 foreign key if ,in fact, that is what I need?
 
 I can provide table structures and information if necessary.
 
 The query is:
 
 $posts_sql = SELECT
 store_subject,
 store_comments,   
 store_date,
 store_tptest, 
 store_by,
 users.user_id,
 users.user_name,
 users.first_name,
 users.last_name
 FROM
 stores
 LEFT JOIN
 users
 ON
 stores.store_by = users.user_id
 WHERE
 stores.store_subject = ' . mysql_real_escape_string($_GET['id']).'
 ORDER BY
 stores.store_date DESC ;
 
 The query dump is:
 
 SELECT store_subject, store_comments, store_date, store_tptest,
 store_by, users.user_id, users.user_name, users.first_name,
 users.last_name FROM stores LEFT JOIN users ON stores.store_by =
 users.user_id WHERE stores.store_subject = 'Noland Park Plaza 3509 S.
 Noland Rd' ORDER BY stores.store_date DESC
 



[PHP-DB] Re: php-db foreign key

2011-08-09 Thread Chris Stinemetz
On Tue, Aug 9, 2011 at 2:55 PM, Frank Flynn fr...@declan.com wrote:

 You already have a foreign key, that is stores.store_by references
users.user_id.  You might not have declared it (which is OK) but if that is
the key you want that is fine.
 I suspect you are seeing an inadvertent Cartesian product.  The way you
have written this query you will get one row from the stores table for each
row in the users table where a store_by = user_id - and because you said
LEFT JOIN you will get one row from the stores table even if there are no
matching rows in the users table.
 So you say you get 3 x the rows you're expecting; are there 3 users that
match that store_by?


No there is only 1 user that match the sotre_by. If the query is not written
correctly do you mind trying to show me how to correctly right it?

When I dump the query and run it in console I get the results I want. Not
sure what I am doing wrong.

mysql SELECT stores.store_subject, stores.store_comments,
stores.store_date, stores.store_tptest, stores.store_by, user
s.user_id, users.user_name, users.first_name, users.last_name FROM stores
LEFT JOIN users ON stores.store_by = users.use
r_id WHERE stores.store_subject = 'Bella Roe 4980 Roe Blvd' ORDER BY
stores.store_date DESC ;
+-++-+-+--+-+---
-++---+
| store_subject   | store_comments | store_date  |
store_tptest| store_by | user_id | user_name
| first_name | last_name |
+-++-+-+--+-+---
-++---+
| Bella Roe 4980 Roe Blvd | test   | 2011-08-09 14:08:05 |
600kbps-3.8mbps |1 |   1 | chrisstinemetz
| Chris  | Stinemetz |
| Bella Roe 4980 Roe Blvd | test1  | 2011-08-09 14:07:49 | 0-250kbps
  |1 |   1 | chrisstinemetz
| Chris  | Stinemetz |
+-++-+-+--+-+---
-++---+
2 rows in set (0.00 sec)


Re: [PHP-DB] Re: php-db foreign key

2011-08-09 Thread Peter Lind

 When I dump the query and run it in console I get the results I want. Not
 sure what I am doing wrong.

Your php code had more than one query running (one inside the other).
It's the outer query that runs twice, not the inner one returning
double the results

-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Re: php-db foreign key

2011-08-09 Thread Chris Stinemetz

 Your php code had more than one query running (one inside the other).
 It's the outer query that runs twice, not the inner one returning
 double the results



Thanks Peter,

Do you have any suggestions on how to fix this?

Thank you,

Chris

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Re: php-db foreign key

2011-08-09 Thread Peter Lind
On 9 August 2011 22:25, Chris Stinemetz chrisstinem...@gmail.com wrote:

 Your php code had more than one query running (one inside the other).
 It's the outer query that runs twice, not the inner one returning
 double the results



 Thanks Peter,

 Do you have any suggestions on how to fix this?

 Thank you,

 Chris


Yes, debug your code and figure out why it's looping twice instead.
For instance, try the other query in the mysql console.


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Re: php-db foreign key

2011-08-09 Thread Chris Stinemetz

 Yes, debug your code and figure out why it's looping twice instead.
 For instance, try the other query in the mysql console.


Thank you! It was the first query. I put a LIMIT 1 on it and now it is
working correctly. I appreciate your help!

Thank you,

Chris

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Re: php-db foreign key

2011-08-09 Thread Peter Lind
On 9 August 2011 22:38, Chris Stinemetz chrisstinem...@gmail.com wrote:

 Yes, debug your code and figure out why it's looping twice instead.
 For instance, try the other query in the mysql console.


 Thank you! It was the first query. I put a LIMIT 1 on it and now it is
 working correctly. I appreciate your help!


You're fixing the symptom, not the problem. Your query was returning
multiple values because something is wrong with the query or your
data. If you don't correct it, the problem will likely just grow
bigger.


-- 
hype
WWW: plphp.dk / plind.dk
LinkedIn: plind
BeWelcome/Couchsurfing: Fake51
Twitter: kafe15
/hype

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Foreign Key Versus Table Index

2008-10-02 Thread J Hussein

Hi,

I'm slightly confused about foriegn keys and indexes on mysql innodb tables.
Foreign key constraints create a reference between two tables and 
indexes make queries on a particular table faster if the index is on a 
field in the where or order by clause.


My question was whether say for the following two tables:

Person Car

Id   Id
Name PersonId
Address  Make
Phone Number   Colour

If I create a foriegn key linking the id field in person and the 
personid field in car, do I need to create another  index in car table 
specifically for the personid field if I was running a query such as:


SELECT Id FROM car WHERE personid={personkeynumber}?

Thanks for your help.

Jemma

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP-DB] Foreign Key Versus Table Index

2008-10-02 Thread Jack van Zanen
I am not up to scratch with innodb, but in oracle
you would have a Primary key  on both the id fields in the Car and person
table and a Foreign key on PersonId linking it to Id in the Person table.

IN your select an index on PersonId would be beneficial if the tables get
large.

Jack

2008/10/2 J Hussein [EMAIL PROTECTED]

 Hi,

 I'm slightly confused about foriegn keys and indexes on mysql innodb
 tables.
 Foreign key constraints create a reference between two tables and indexes
 make queries on a particular table faster if the index is on a field in the
 where or order by clause.

 My question was whether say for the following two tables:

 Person Car

 Id   Id
 Name PersonId
 Address  Make
 Phone Number   Colour

 If I create a foriegn key linking the id field in person and the personid
 field in car, do I need to create another  index in car table specifically
 for the personid field if I was running a query such as:

 SELECT Id FROM car WHERE personid={personkeynumber}?

 Thanks for your help.

 Jemma

 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php




-- 
J.A. van Zanen


Re: [PHP-DB] Foreign Key Versus Table Index

2008-10-02 Thread Bastien Koert
On Thu, Oct 2, 2008 at 6:50 AM, Jack van Zanen [EMAIL PROTECTED] wrote:

 I am not up to scratch with innodb, but in oracle
 you would have a Primary key  on both the id fields in the Car and person
 table and a Foreign key on PersonId linking it to Id in the Person table.

 IN your select an index on PersonId would be beneficial if the tables get
 large.

 Jack

 2008/10/2 J Hussein [EMAIL PROTECTED]

  Hi,
 
  I'm slightly confused about foriegn keys and indexes on mysql innodb
  tables.
  Foreign key constraints create a reference between two tables and indexes
  make queries on a particular table faster if the index is on a field in
 the
  where or order by clause.
 
  My question was whether say for the following two tables:
 
  Person Car
 
  Id   Id
  Name PersonId
  Address  Make
  Phone Number   Colour
 
  If I create a foriegn key linking the id field in person and the personid
  field in car, do I need to create another  index in car table
 specifically
  for the personid field if I was running a query such as:
 
  SELECT Id FROM car WHERE personid={personkeynumber}?
 
  Thanks for your help.
 
  Jemma
 
  --
  PHP Database Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 


 --
 J.A. van Zanen


Jenna,

FKs are not to create relationships but act as constraints inside the data
base. What that means is that for a record to be created that has a FK in
another table, that FK'ed record MUST exist in the table before you can add
that record.

Ex. AN Order table and a Customer table

If the Order table references the Customer table as a FK on the CustomerID
field, the CustomerId record MUST exist in the table before the order table
can be filled.

It does not alleviate the need to have a primary key on the other table.

http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.htmlfor
more details

-- 

Bastien

Cat, the other other white meat


RE: [PHP-DB] foreign key problem

2001-01-31 Thread Chris Andrew

A foreign key value can be null, if it suits the data application - or that
is what I've always been taught.

Here is a text book definition of Referential Integrity which was spoon fed
to me by the Open University when studying their RDBMS course:

"Referential Integrity - If a relation (table), R2 has a foreign key, F,
that references the primary key, P, in another relation (table), R1, then
every R2.F entry must either be a value equal to an R1.P primary key value
or be null"

Regards,
Chris

 -Original Message-
 From: Bob Hall [mailto:[EMAIL PROTECTED]]
 Sent: 31 January 2001 01:53
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP-DB] foreign key problem


 hello all!
 i have a little problem ,hope someone can help me out
 the problem is :
 let i have two tables T1 and T2 ,now T1 has following
 fields
 cntryid
 cntryname
 cntrycode etc.
 now cntryid is the primary key now i want to make the
 cntryid a foreign key in table T2 .so how can i do it
 plz help me .
 msjamal

 A column is a foreign key because it contains only values found in
 the referenced key, and no NULLs. Design your database so that the
 foreign key column contains only values from cntryid.

 If you want to know how to declare a referenced key/foreign key
 relationship, you will have to specify what RDBMS you are using.

 Bob Hall

 Know thyself? Absurd direction!
 Bubbles bear no introspection. -Khushhal Khan Khatak

 --
 PHP Database Mailing List (http://www.php.net/)
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 To contact the list administrators, e-mail: [EMAIL PROTECTED]


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP-DB] foreign key problem

2001-01-31 Thread Bob Hall

Yes sir, you are correct. Thank you for correcting me. In practice, a 
NULL in a foreign key almost always means an orphan record. In most 
applications the designer will want to use the NOT NULL constraint.

Bob Hall

A foreign key value can be null, if it suits the data application - or that
is what I've always been taught.

Here is a text book definition of Referential Integrity which was spoon fed
to me by the Open University when studying their RDBMS course:

"Referential Integrity - If a relation (table), R2 has a foreign key, F,
that references the primary key, P, in another relation (table), R1, then
every R2.F entry must either be a value equal to an R1.P primary key value
or be null"

Regards,
Chris

   -Original Message-
   From: Bob Hall [mailto:[EMAIL PROTECTED]]
   Sent: 31 January 2001 01:53
   To: [EMAIL PROTECTED]
   Subject: Re: [PHP-DB] foreign key problem
  
  
   hello all!
   i have a little problem ,hope someone can help me out
   the problem is :
   let i have two tables T1 and T2 ,now T1 has following
   fields
   cntryid
   cntryname
   cntrycode etc.
   now cntryid is the primary key now i want to make the
   cntryid a foreign key in table T2 .so how can i do it
   plz help me .
   msjamal
  
   A column is a foreign key because it contains only values found in
   the referenced key, and no NULLs. Design your database so that the
   foreign key column contains only values from cntryid.
  
   If you want to know how to declare a referenced key/foreign key
   relationship, you will have to specify what RDBMS you are using.
  
   Bob Hall
  
   Know thyself? Absurd direction!
   Bubbles bear no introspection. -Khushhal Khan Khatak
  
   --
   PHP Database Mailing List (http://www.php.net/)
   To unsubscribe, e-mail: [EMAIL PROTECTED]
   For additional commands, e-mail: [EMAIL PROTECTED]
   To contact the list administrators, e-mail: [EMAIL PROTECTED]


--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Know thyself? Absurd direction!
Bubbles bear no introspection. -Khushhal Khan Khatak

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]