karthik80c
asked on
Trigger in My SQL
I have a website where the Users enter the product information by Single entry or through the batch upload of CSV file. In both cases the records get inserted to the same table which is in My SQL database.
The information is then retrieved and shown in the website too. There is a product id column which has 20 characters. But when we are displaying it in the website we show only the first 10 records. As the next 10 are critical and is not displayed. Though the product ID is a unique column the first 10 characters are not unique. So I will be attaching product id +0001 when the information is displayed outside. So I prefer to insert a column in the existing table. The column will get update with product id +0001 on the first entry. Whenever there is a duplicate record gets inserted in the product id by matching the first 10 characters the sequence should be predicted +0002.
So I need a trigger and sequence code in mysql for this. Please help.
The information is then retrieved and shown in the website too. There is a product id column which has 20 characters. But when we are displaying it in the website we show only the first 10 records. As the next 10 are critical and is not displayed. Though the product ID is a unique column the first 10 characters are not unique. So I will be attaching product id +0001 when the information is displayed outside. So I prefer to insert a column in the existing table. The column will get update with product id +0001 on the first entry. Whenever there is a duplicate record gets inserted in the product id by matching the first 10 characters the sequence should be predicted +0002.
So I need a trigger and sequence code in mysql for this. Please help.
Please rephrase your question. Post a concise and complete example. Include sample data..
Is the product ID numeric or alphanumeric? You want a trigger to fire on an insert to the table or an update to the table or both events? When you say "attaching +0001," do you mean to append to the value of product ID four characters of "0001"? I want to make sure you aren't talking about prepending it or mathematically adding the value of 0001 to the ID.
This gives information about creating triggers:
http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html
This gives information about creating triggers:
http://dev.mysql.com/doc/refman/5.0/en/create-trigger.html
ASKER
Dear Phil
The product ID is alphanumeric.
The situation is like this
Product : Apple
Product ID : UID903456790090
Product : Orange
Product ID :UID903456790093
These two products have the first 10 character same.
I am displaying only the first 10 to the customer for some reason.
When I am displaying it if the customer calls in and says the product ID he will be able to say only the first 10
So my search string on the database will retrieve two records.
So am planning to attach a sequence to the product ID with 0001 for the first record and any duplicate product ID for the first 10 character will have it 0002. I will be creating a separate column for this sequence and while displaying it in the website I will be attaching them.
The product ID is alphanumeric.
The situation is like this
Product : Apple
Product ID : UID903456790090
Product : Orange
Product ID :UID903456790093
These two products have the first 10 character same.
I am displaying only the first 10 to the customer for some reason.
When I am displaying it if the customer calls in and says the product ID he will be able to say only the first 10
So my search string on the database will retrieve two records.
So am planning to attach a sequence to the product ID with 0001 for the first record and any duplicate product ID for the first 10 character will have it 0002. I will be creating a separate column for this sequence and while displaying it in the website I will be attaching them.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.