Jump to content

How to generate unique product key/id?


dwex

Recommended Posts

My table looks like this..

 

`guns_id` int(255) NOT NULL auto_increment,
  `guns_name` varchar(255) collate latin1_general_ci NOT NULL,
  `guns_price` int(255) NOT NULL,
    PRIMARY KEY  (`guns_id`)

 

I want to add a product key that is unique through out the whole database as I have other products other than guns aswell.

 

 

Link to comment
Share on other sites

I'm guessing you have other items in the Database such as car_id, car_name, car_price and other stuff.

 

How about giving them all an item_id? indestead of giving each catergory unique ID's?

 

If this is not the case, would you care to explain how your Database is structured?

 

Regards, PaulRyan.

Link to comment
Share on other sites

Would you be able to show me how the database tables look currently?

 

Are you wanting to have the ID be a number or letters, or both?

Would is be possible to merge the items tables into 1 big table?

 

If not you could just add a new field to all of the items tables and call it item_id a said before and then just add a unique number and/or letter combo manually...

 

Regards, PaulRyan.

Link to comment
Share on other sites

something like that.

 

-- 
-- Table structure for table `headbands`
-- 

CREATE TABLE `headbands` (
  `headbands_id` int(250) NOT NULL auto_increment,
  `headbands_name` varchar(250) collate latin1_general_ci NOT NULL,
  `headbands_price` varchar(250) collate latin1_general_ci NOT NULL,
  `headbands_description` varchar(1000) collate latin1_general_ci NOT NULL,
  `headbands_image` varchar(250) collate latin1_general_ci NOT NULL,
  `headbands_stock` int(255) NOT NULL,
  `headbands_time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`headbands_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=15 ;

-- 
-- Dumping data for table `headbands`
-- 


-- --------------------------------------------------------

-- 
-- Table structure for table `helmet`
-- 

CREATE TABLE `helmet` (
  `helmet_id` int(255) NOT NULL auto_increment,
  `helmet_name` varchar(255) collate latin1_general_ci NOT NULL,
  `helmet_price` int(255) NOT NULL,
  `helmet_description` varchar(1000) collate latin1_general_ci NOT NULL,
  `helmet_image` varchar(255) collate latin1_general_ci NOT NULL,
  `helmet_stock` int(255) NOT NULL,
  `helmet_time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`helmet_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ;

-- 
-- Dumping data for table `helmet`
-- 


-- --------------------------------------------------------

-- 
-- Table structure for table `shirts`
-- 

CREATE TABLE `shirts` (
  `shirts_id` int(250) NOT NULL auto_increment,
  `shirts_name` varchar(100) collate latin1_general_ci NOT NULL,
  `shirts_price` varchar(150) collate latin1_general_ci NOT NULL,
  `shirts_description` varchar(1000) collate latin1_general_ci NOT NULL,
  `shirts_image` varchar(250) collate latin1_general_ci NOT NULL,
  `shirts_stock` int(255) NOT NULL,
  `shirts_time` timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
  PRIMARY KEY  (`shirts_id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=20 ;

Link to comment
Share on other sites

CREATE TABLE categories (
  category_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT,
  category_name VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  PRIMARY KEY (category_id)
) ENGINE=INNODB;

CREATE TABLE items (
  item_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
  category_id SMALLINT UNSIGNED NOT NULL,
  item_name VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  item_price DECIMAL(5,2) UNSIGNED NOT NULL,
  item_description VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL,
  item_image BLOB NOT NULL,
  item_stock SMALLINT UNSIGNED NOT NULL,
  item_time DATETIME NOT NULL,
  PRIMARY KEY (item_id),
  FOREIGN KEY (category_id) REFERENCES categories (category_id)
) ENGINE=INNODB;

 

If there is any information specific to some item create a new table and let it hold a reference to the items table.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.