On 23-Aug-2001 Tim Cowan wrote:
> Hi
> 
> Is it possible to use 2 or more fields to become the primary key.  I have a
> table
> 
> CREATE TABLE tmptraining (
>   rowid int(10) unsigned NOT NULL auto_increment,
>   sid char(32) NOT NULL default '',
>   expiry date NOT NULL default '0000-00-00',
>   arenaid tinyint(1) unsigned NOT NULL default '0',
>   time time NOT NULL default '00:00:00',
>   date date NOT NULL default '0000-00-00',
>   equip enum('Y','N') NOT NULL default 'N',
>   PRIMARY KEY  (rowid)
> )
> 
> and I want to constrain the information on four fields; arena, time, date
> and sid.  That way if someone clicks the refresh or reload button it will
> not add another row, if all FOUR of the fields have the same value as
> another row.  Is there a way to do this?
> 


Yes.

mysql> desc hist_hits;
+---------+-----------------------+------+-----+------------+-------+
| Field   | Type                  | Null | Key | Default    | Extra |
+---------+-----------------------+------+-----+------------+-------+
| hitdate | date                  |      | PRI | 0000-00-00 |       |
| wmid    | smallint(5) unsigned  |      | PRI | 0          |       |
| site    | char(2)               |      | PRI | sh         |       |
| urlid   | bigint(20) unsigned   |      | PRI | 0          |       |
| rurlid  | bigint(20) unsigned   |      | PRI | 0          |       |
| hits    | mediumint(8) unsigned |      |     | 0          |       |
| clicks  | smallint(5) unsigned  |      |     | 0          |       |
+---------+-----------------------+------+-----+------------+-------+
7 rows in set (0.00 sec)

localhost.dread$ mysqldump -d WS hist_hits 
# MySQL dump 8.14
#
# Host: localhost    Database: JAWS
#--------------------------------------------------------
# Server version        3.23.38

#
# Table structure for table 'hist_hits'
#

CREATE TABLE hist_hits (
  hitdate date NOT NULL default '0000-00-00',
  wmid smallint(5) unsigned NOT NULL default '0',
  site char(2) NOT NULL default 'sh',
  urlid bigint(20) unsigned NOT NULL default '0',
  rurlid bigint(20) unsigned NOT NULL default '0',
  hits mediumint(8) unsigned NOT NULL default '0',
  clicks smallint(5) unsigned NOT NULL default '0',
  PRIMARY KEY  (wmid,hitdate,urlid,rurlid,site),
  KEY idx_d (hitdate)
) TYPE=MyISAM;

localhost.dread$ 

Regards,
-- 
Don Read                                       [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to 
   steal the neighbor's newspaper, that's the time to do it.
                            (53kr33t w0rdz: sql table query)

---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to