RE: [SPAM] Re: [PHP-DB] DB table creation question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Does this seem to be correct? With this if value was inserted into a
table will the tables with the FK's automatically be updated? Here is
the DB design as I have it now. Let me know if all is correct please.

CREATE TABLE customer_info (
       cust_id int (6) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
       first_name varchar (50) NOT NULL,
       last_name varchar (50) NOT NULL,
       address varchar (50) NOT NULL,
       address2 varchar (50) NULL,
       city varchar (50) NOT NULL,
       state varchar (50) NOT NULL,
       zip varchar (50) NOT NULL,
       home_phone varchar (15) NOT NULL,
       work_phone varchar (15) NULL,
       other_phone varchar (15) NULL,
       email varchar (50) NOT NULL,
       );
CREATE TABLE product_info (
       product_id int (6) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
       cust_id int (6) NOT NULL,
       model varchar (50) NOT NULL,
       serial varchar (20) NULL,
       FOREIGN KEY (customer_info_cust_id),
        REFERENCES customer_info(cust_id),
       ON UPDATE CASCADE ON DELETE RESTRICT,
       INDEX (cust_id),
       FOREIGN KEY (cust_id),
       REFERENCES customer_info(cust_id),
       );
CREATE TABLE warranty_info (
       warranty_id int (6) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
       product_id int (6) NOT NULL,
       cust_id (6) NOT NULL,
       mfg_warranty tinyint (1) NOT NULL default '1',
       gold_warranty tinyint (1) NOT NULL default '0',
       gold_warranty_id int (16) NULL,
       FOREIGN KEY (customer_info_cust_id),
        REFERENCES customer_info(cust_id),
       ON UPDATE CASCADE ON DELETE RESTRICT,
       INDEX (cust_id),
       FOREIGN KEY (cust_id),
       REFERENCES customer_info(cust_id),
       FOREIGN KEY (product_info_product_id),
        REFRENCES product_info(product_id),
       ON UPDATE CASCADE ON DELETE RESTRICT,
       INDEX (product_id),
       FOREIGN KEY (prod_id),
        REFRENCES product_info (product_id),
       );
CREATE TABLE rma_info (
       rma_id int (6) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
       assigned_to varchar (50) NULL,
       logged_by varchar (50) NULL,
       date datetime NOT NULL,
       time_spent datetime (6) NULL,
       status varchar (50) NOT NULL,
       priority varchar (50) NULL,
       closed_by varchar (50) NULL,
       completed_by varchar (50) NULL,
       date_closed datetime (6) NULL,
       billable tinyint(1)NULL,
       billed tinyint (1) NULL,
       cost varchar (6) NULL,
       last_modified_by varchar (50) NULL,
       last_modified_date datetime NULL,
       );

  

-----Original Message-----
From: Matthew McNicol [mailto:matthew@xxxxxxxxxxxxxxxxxx] 
Sent: Sunday, July 18, 2004 5:46 PM
To: Vincent Jordan
Cc: php-db@xxxxxxxxxxxxx
Subject: [SPAM] Re:  DB table creation question


use the mysql 'auto increment' on a 'int' 'customer_id' field to 
generate a unique customer id.

the RMA number is associated with a 'customer_id' since the 
'customer_id' field is in both the customers table and the RMA table. 
Note that currently you have 'custid' and 'Customerid' respectively 
which you should change so that they are uniform (it helps with database

maintenance is foreign keys are spelt the same as the primary key 
equivalent).

to assign a product to a customer, first create a products table which 
defines each product. each product would have a unique 'product_id'. 
second, create a table which will link the products (zero, one or more) 
a customer has selected to the 'rma_id'. such tables would have the 
following structure:

table: product
product_id
product_desc
...

table: rma_product
rma_id
product_id


table: customer
customer_id
firstname
lastname
...

table: rma
rma_id
assignedto
loggedby
customer_id
...


Do you follow? Do you understand in what order you should populate the 
tables and how you can now create SQL queries to get the information you

need?



Vincent Jordan wrote:
> I am creating a database to keep track of our warranty returns.
> Currently we do not have anything to track warranty info besides a big
> excel file. I would like to keep customer data, product info and RMA
> data in separate tables but still keep them related. 
>  
> If I had table customers:
> custid
> Firstname
> Lastname
> Address
> Address2
> City
> State
> Zip
> Phone
> Email
>  
> And table RMA
> Rmaid
> Assignedto
> Loggedby
> Customerid
> Date
> Timespent
> Status
> Priority
> Closedby
> Completedby
> Dateclosed
> Billable
> Billed
> Cost
> Lastmodifiedby
> Lastmodifieddate
>  
> What I want to ensure is that if john smith fills out an RMA request
> online a customer id is assigned to John, the RMA number is associated
> with Johns customerid and I need to figure out how to assign a product
> to John. Also if john has more than one product assign products so
when
> I pull up Johns information I can see all of Johns products owned.
>  
> I am running mysql latest version.. Any help would be greatly
> appriciated
>  
> 

-- 

_________________
Matthew McNicol

yellowmarker.co.uk
PHP / MySQL web development

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

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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux