473,394 Members | 1,813 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

how to create a fixed size table in mysql

126 64KB
I'm yet a learner so, i would be glad to everyone for their contribution in me gaining knowledge:)

I would like to known if we can create a fixed size table in mysql, if yes, then how do we do it?
Oct 31 '12 #1
17 5437
Rabbit
12,516 Expert Mod 8TB
What do you mean by fixed size table?
Oct 31 '12 #2
PreethiGowri
126 64KB
example - i want just 100 entries to be made into it, and i want the table to work in the form of FIFO when i make an 101 th entry
Oct 31 '12 #3
Rabbit
12,516 Expert Mod 8TB
You can use an insert trigger to run a count and delete operation.
Oct 31 '12 #4
PreethiGowri
126 64KB
i'm new to that can you guide me please
Nov 1 '12 #5
Rabbit
12,516 Expert Mod 8TB
Here is MySQL's documentation on triggers: http://dev.mysql.com/doc/refman/5.0/en/triggers.html
Nov 1 '12 #6
PreethiGowri
126 64KB
how do we put a count for insert in trigger query?
Nov 2 '12 #7
Rabbit
12,516 Expert Mod 8TB
It's just a simple select count all query.
Nov 2 '12 #8
PreethiGowri
126 64KB
Expand|Select|Wrap|Line Numbers
  1. DELIMITER $$ 
  2.  create  TRIGGER MyTrigger before insert on purchased
  3.  delete from purchased where count = 3
  4.  $$
  5.  DELIMITER;
  6.  
the count(*) value is aliased to count in my above query.
This query isn't working for me, can you correct this please:(
Nov 2 '12 #9
PreethiGowri
126 64KB
Finally done with this home work of trigger:):)

Expand|Select|Wrap|Line Numbers
  1. "create  TRIGGER MyTrigger before insert on purchased
  2.  FOR EACH ROW 
  3.  BEGIN 
  4.  if count  > 3 then 
  5.  delete from purchased
  6.  insert into purchased values(id, name , quantity);
  7.  END if;
  8.  END ;
Thanks for your guidance Rabbit:):)
Nov 2 '12 #10
PreethiGowri
126 64KB
do we have an option of if else in trigger query?
Nov 2 '12 #11
Rabbit
12,516 Expert Mod 8TB
Yes, you can use if else in a trigger.
Nov 2 '12 #12
PreethiGowri
126 64KB
i cant delete a row from the table before inserting new records to the same table. its showing " cant update trigger/function because it is already being used by trigger/function"...
help?
Nov 3 '12 #13
Rabbit
12,516 Expert Mod 8TB
Please post your most current code.
Nov 3 '12 #14
PreethiGowri
126 64KB
Expand|Select|Wrap|Line Numbers
  1. create  TRIGGER MyTrigger before insert on purchased
  2. FOR EACH ROW
  3. BEGIN
  4. if count  > 6 then
  5. delete from purchased limit 1
  6. elsif count <= 6 then
  7. insert into purchased (RFID_NO, name, price, quantity, totalPrice, purchase_date, expiry,customer_name,ph_no) (select RFID_NO, name, price, quantity, totalPrice , NOW() ,DATE_ADD(NOW(), interval 1 month),customer_name,ph_no from cart);
  8. END if; 
  9. END ;
  10.  
After this i do a multiple row insertion
Nov 5 '12 #15
Rabbit
12,516 Expert Mod 8TB
Your syntax is off. This is off the top of my head as I don't have MySQL to test it against where I am currently. The basic syntax will look kind of like this:
Expand|Select|Wrap|Line Numbers
  1. DELIMITER |
  2.  
  3. CREATE TRIGGER triggerName
  4. BEFORE INSERT ON tableName
  5. FOR EACH ROW
  6.  
  7. BEGIN
  8. DECLARE num_rows INTEGER;
  9.  
  10. SELECT COUNT(*)
  11. INTO num_rows
  12. FROM tableName;
  13.  
  14. IF num_rows > 6 THEN
  15.    DELETE FROM tableName LIMIT 1;
  16. END IF;
  17.  
  18. |
  19. DELIMITER ;
There's no need to do another insert. It's already going to insert.
Nov 5 '12 #16
PreethiGowri
126 64KB
i have a doubt can multiple tables of same database have triggers??
Nov 6 '12 #17
Rabbit
12,516 Expert Mod 8TB
I'm not sure what that means but if there's a hard limit on the number of triggers you can have, it would be a fairly high number. But I doubt you have any other triggers than this one since you said you said you were new to triggers. So I must have misunderstood your meaning.
Nov 6 '12 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: dev | last post by:
how create a temp table as a copy of a existing table and then update1 field and insert the hole temp table back in the existing table? please any help? if i have 10 fields in 1 record and...
0
by: nm | last post by:
Is it possible to MERGE innodb tables? Can't find docs on mysql.com In replication. I guess I can update the slave if the master is not responding, right? Shall I 'stop slave' before , in case...
3
by: Michael Lauzon | last post by:
This is not for a class, I have a group on SourceForge, this is what one of the Developers is asking; the more advanced you can make it right off all the better!: Can someone please create...
2
by: Danny | last post by:
Hello I am trying to keep a table or row a fixed size. I have a javascript that assigns different images to the SRC of the main image, but the table will resize whne there is a smaller height...
11
by: Linny | last post by:
Hi, I need some help in declaring an array of pointers to array of a certain fixed size. I want the pointers to point to arrays of fixed size only (should not work for variable sized arrays of the...
0
by: Ken Varn | last post by:
I have a managed C++ assembly in which I need to interact with some 'C' APIs that take fixed size 'C' data blocks. I need to wrap these data blocks into a managed object. It seems like a lot of...
2
by: neuneudr | last post by:
Hi everybody, I'm scratching my head with a CSS problem. I want to have the following (the two pics have these size for a good reason, the whole point of the page is basically to show these...
3
by: patl | last post by:
Hi all, I am trying to write a terminal emulator using Javascript + AJAX and I need to create an 80x25 table (each cell contains 1 character) in which I can update the contents of each cell...
1
by: shofu_au | last post by:
Hi Group, I am trying to define a class that has a fixed size array of a structure containing a fixed size array of a structure. I am using System.Runtime.InteropServices and trying to define...
3
by: jerrygadd | last post by:
Hi can anyone please help? I have a need to make a table of fixed size, containing three rows, where the middle row auto expands to fill the remaining space between the top and bottom rows. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.