A Date Column That Auto-updates When Any Column In The Row Is Updated
Let's say I have a table with several columns.
I would like to add a column called "date last updated".
How this would work is that any time one of the other columns in that row was updated, the 'date last updated' column would update.
I *know* how to do this with PHP, but here is the special part...
Is there a way to have this automatically just within MySQL, so that EVEN IF if update a column manually through the command line or PHPmyAdmin, the 'date last updated' field updates.
View Complete Forum Thread with Replies
Related Forum Messages:
Updated Column?
is there a way to obtain only the affected columns after an update query? After an update query, that involves 10 columns, I know that only 2 columns are really updated (because the values of the other cols don't change). I need to know the names of that changed cols, for logging purpose.
View Replies !
Auto Column
I want to select a single row called "row1" but let mysql auto append a NON-exist column call "row2" of it. And i want that non-exist column be auto-increment. how to? If i "select row1 from mytable", then i get ----------- - row1 - ----------- - a - - b - - c - - d - ----------- but i want: ---------------------- - row1 -- row1 - ---------------------- - a - 1 - - b - 2 - - c - 3 - - d - 4 - ----------------------
View Replies !
Can I: Export Column, Optimize & Fill New Column With Value To Original Column?
I have a database with over 40,000 rows and 28 columns (learned how to import large files by changing php.ini!). Using Excel, I am able to: (A) copy and paste original column (e.g., SIZE_TEXT) (B) ALONG with each records' UNIQUE_KEY, (C) sort SIZE_TEXT column, (D) filter for unique values, (E) fill new column with its SIZE_TEXT__KEY, and then (F) import the new SIZE_TEXT_KEY value into the database by creating a new column or pasting over the columns original value. However, I think this can be performed, with less potential for error, using phpMyAdmin, but I haven't found anything demonstrating how to perform these actions. I searched the terms optimization and normalization. I am hoping one can use phpMyAdmin to: 1) create a new table with export column of the original table (SIZE_TEXT_TABLE), 2) sort new table for duplicates and show only unique values, then 3) import the column results into each Unique Records original column (SIZE_TEXT) 4) link new column values to Foreign Key (the Parent Table's SIZE_TEXT_KEY)
View Replies !
Multiple Auto Increments In One Column
Is it possible to have multiple auto increments in one column? Say I have two tables... 1. table 'messageboards' with fields ('id' , 'name') 2. table 'messagethreads' with fields ('id' , 'messagethread' , 'messageboard_id') The 'messagethreads.id' column could have multiple auto increments. Then I could easily query a messageboard with ("SELECT * FROM messagethreads WHERE messageboard_id = 1 ORDER BY id"). Each thread would return an id starting from number 1. If MySQL does not support multiple auto increments, I guess the only other solutions are... - Create a new table for every 'messageboard' with an auto increment column and join them to 'messagethreads' for a query. Id like to use as few tables as possible though. - Use transactions or table locking to generate the auto increment value. Id like to not use either for performance reasons.
View Replies !
Alter Column To Auto Increment
I have a table that has data in it. The table had an auto increment column but I had to take auto increment off to insert some old data from a backup site. I get an error when I try to alter table to make the column auto increment again. I need some assistance.
View Replies !
Is It Possible To Force A Zero Into Auto-increment Column?
I want to add MySQL support to a SQL Server application that contains many IDENTITY (auto-increment) columns with zero in the id field. We use that as a proxy for no entry to keep joins from dropping out entries with no value. Is there any way to insert a zero into an auto-increment column? I know you can specify a specific value in the insert if it does not already exist and if it's 0 or no entry is specified in the insert then you get the next available value. How would you force a zero into the column?
View Replies !
Auto Increment Based On A Column Value?
I did a bit of searching but couldn't find anything, so: If I have a table structure similar to this: Code: table: productImages idfilenameproductIdorder 110234.jpg121 213702.jpg122 323674.jpg123 498373.jpg151 544126.jpg152 Would it be possible to create an auto increment value in the 'order' column, based on the 'productId' column? As an example, if I insert another record with filename = 12345.jpg and productId = 12, then it would set order = 4 based on the previous three entries for that product?
View Replies !
Alter A Primary Key Auto Increment Column
I need to change my primary key column type from smallint to int. I have tried: ALTER TABLE livegroup MODIFY id INT UNSIGNED NOT NULL AUTO_INCREMENT; But get an error message certainly since my id-column is primary key and references other tables as well. This is my table definition livegroup ( id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, type VARCHAR(60) NOT NULL, name CHAR(60) NOT NULL, public TINYINT NOT NULL, creator SMALLINT UNSIGNED NOT NULL, lastmodified TIMESTAMP(8), PRIMARY KEY (id), INDEX (creator), FOREIGN KEY (creator) REFERENCES user (id) ON DELETE CASCADE ) TYPE=INNODB; livegroups ( data_id SMALLINT UNSIGNED NOT NULL, livegroup_id SMALLINT UNSIGNED NOT NULL, PRIMARY KEY (data_id, livegroup_id), INDEX (data_id), INDEX (livegroup_id), FOREIGN KEY (data_id) REFERENCES livedata (id) ON DELETE CASCADE, FOREIGN KEY (livegroup_id) REFERENCES livegroup (id) ON DELETE CASCADE ) TYPE=INNODB;
View Replies !
How To Disable Auto Truncation Of Char Binary Column
Why is a single space truncated in the following example? Leif alter table CURRENCY change column THOUSANDS_SEP THOUSANDS_SEP char(1) binary not null , type=MyISAM UPDATE CURRENCY SET THOUSANDS_SEP = ' ' WHERE NAME = 'SEK' SELECT LENGTH(THOUSANDS_SEP) AS L FROM CURRENCY WHERE NAME = 'SEK' Result: L = 0
View Replies !
Auto Increment Fields Get Updated
I need to use an auto increment field, but I dont know how they get updated in a query. If I had say: INSERT INTO `table` VALUES ( '1','2','3' ) and the 3 row was auto increment, would i put a number, or just put nothing.
View Replies !
Create New Table That Auto Updates
I have a table (TABLE 1)that measures air mysqlerature and creates new records every 10 mins. I have created a new table (TABLE 2) that shows the latest row from TABLE 1. I need TABLE 2 to update its record to the latest row from TABLE 1 automatically or by a defined time period. How is this achieved
View Replies !
Selecting From Column A Where Column B Matches Column A Twice?
Here's a table called Creatures containing Creatures and EntryIDs: Code: [Creatures] Creature EntryID ================== fish 100 cat 100 fish 200 bird 200 pig 300 bird 400 I would like to select all EntryIDs that contain both "fish" and "bird". From the above table, "200" should be returned, seeing as both fish and bird are the only rows that both use the same EntryID. How can I do this? Do I need to use Group By or Left Join or something?
View Replies !
Column As A Date
In a certain table, I would like a column to be the date. When I insert a record, I will not want to insert the date but it should be populated automatically. Can this be done in MySQL?
View Replies !
Date Range Without Date Column
Suppose I have a table that says on which days I should eat certain foods: +----+-------------+-----+-----+-----+-----+-----+-----+-----+-----+ | Id | Name | Qty | Mon | Tue | Wed | Thu | Fri | Sat | Sun | +----+-------------+-----+-----+-----+-----+-----+-----+-----+-----+ | 1 | Carrots | 3 | T | T | T | T | T | T | T | | 2 | Cauliflower | 1 | T | T | T | T | T | T | T | | 3 | Broccoli | 2 | T | T | T | T | T | T | T | | 4 | Peas | 10 | F | F | F | F | F | T | T | | 5 | Potatoes | 1 | T | T | T | F | F | F | F | +----+-------------+-----+-----+-----+-----+-----+-----+-----+-----+ And suppose this is the calendar: August 2006 MonTueWedThuFriSatSun 123456 78910111213 14151617181920 21222324252627 28293031 For the days August 8 through August 10 inclusive, how can I figure out how much food I should eat with an SQL statement? The answer should be: 9 carrots 3 cauliflowers 6 broccoli 2 potatoes
View Replies !
Default Value On Date Column
Using MySQL control center, I created a MySQL database table with a column of Date type. It always give the a Default value (0000-00-00) even null is allowed. I tried remove the default value and it comes back by itself. So if I don't supply a value when insert, the default is used. Query IS NOT NULL will not exclude this record. Now, In VB (with ADO/MyOLEDB), I did the exact query trying to filter out the null record. But I still get the record just like in Control Center. BUT, the value on this column is "NULL". How can I leave the Date field as null if no value is supplied?
View Replies !
Date Column Null?
I'm importing a dbf formatted table into mysql. The table has a date column but a lot of the dates are left out. I made sure that the target table's date column is set to 'allow null'. For some reason, the rows in the source table where the date column is blank get imported as '1/1/0001'. And that doesn't test as NULL either. I am using navicat as my mysql gui. Any thoughts about what 1/1/0001 really means and why that happens? And is there a simple way to convert any appearances of 1/1/0001 to null? I've tried things like update table set arrival_date = null where arrival_date = '1/1/0001' and that runs ok but doesn't work...it reports that it affects '0 rows' so the 1/1/0001 that I am seeing must somehow be actually stored as something other than 1/1/0001. And I know that 1/1/0001 is outside the allowed date range for mysql ... I'm sure that's a clue but I still can't figure out the answer.
View Replies !
Reformatting The Date Column
is there a way i can alter my column in the table instead of being yyyy-mm-dd it is mm/dd/yyyy or mm-dd-yyyy? like change it from datetime to date or setting some other parameter? I am not sure if I am being clear, but basically i don't want to format the date after retrieving it, can I somehow set the source to the right format?
View Replies !
Adding A Column Number To A Date
I want to add a column to a date. i.e. date('Ymd', mktime(0, 0, 0, $expmonth , $expday + $paymentterms, $expyear)); this shows a column paymentterms is added to the day part of the date. I have achieved this in php but if I can do it in sql I will be able to reduce the number of results as I want the sql to not select records where the date+column less than today.
View Replies !
Selecting Certain Dates From Date Column
I wonder how this can be done, data is like this +---------------------+ | whenstamp | +---------------------+ | 2005-02-21 12:27:54 | | 2005-02-21 12:27:54 | | 2005-02-21 12:27:55 | | 2005-02-21 12:42:55 | +---------------------+ 4 rows in set (0.00 sec) mysql> I tried something like this :: $this_month = mysqli_query($dbcon,"select date_format(whenstamp,'%d-%m-%Y') as datex from logs where %m = '02'"); Basically I want to retrive records corresponding to the current month, I know I have hardcore '02' in their but that was just for testing and getting started.
View Replies !
Select Date And Time In Same Column
I have table called mytable and there I have column named time example: time 2006-07-10 10:28:06 2006-08-18 20:48:22 2006-09-15 12:11:41 2006-10-12 23:06:02 is there any possibles that I can make query example: SELECT *FROM mytable WHERE date BETWEEN 2006-07-10 AND 2006-09-15 AND time BETWEEN 10:28:06 AND 12:11:41 My point is can I make query where I first find between date and after that I make query where I find between time when information is in the same column?
View Replies !
How To Keep A Table Ordered By A 'date' Column
how should I keep my "deliveries" table sorted by "date" field ? I found a solution with " ALTER TABLE 'deliveries' ORDER BY 'date' " after every INSERT I make , but I'm not sure it's the fastest way. I couldn't find the algorithm used for sorting so I'm not sure it's optimised for sorting where only one record is out of it's place.
View Replies !
Compare Date Type Column
is there anyway i can compare 3 or more date type column? let's say i have ------------------------------------------------ date1 | date2 | date3 ------------------------------------------------ 2006-06-01 | 2006-06-15 | 2006-09-19 ------------------------------------------------ can i just get the earliest date by command line? select XXXXX(date1,date2,date3) <--returns '2006-06-01 ' select YYYYY(date1,date2,date3) <--returns '2006-09-19 '
View Replies !
Using DATE_ADD With Date Type Column
MySQL Version - 4.0.17 Is it possible to use DATE_ADD with a "date" type column? I need to select all of the records that are exactly 11 months old... I have the following: SELECT fname, sname from Calendar_Appointment_Dates Where DATE_ADD(appt_date, INTERVAL 11 MONTH) = CURRENT_DATE() But this doesnt seem to return any records, despite the tbl containing nearly 6000 rows......
View Replies !
Date Extraction Issue From Datetime Column
I would also like to only provide a date in the where clause and not a timestamp (the field is of type datetime). I have tried using the date function but it does not appear to work. I tested the date function as per mysql: manual(http://dev.mysql.com/doc/mysql/en/d...-functions.html) but I get the following error: SQL-query: SELECT DATE( '2003-12-31 01:02:03' ) MySQL said: #1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '('2003-12-31 01:02:03')' at line 1
View Replies !
ERROR “80040E38 When Updating A DATE Column.
getting an ERROR “80040E38 Row Cannot be located for Update. Some Values may have been changed since it was last read.” when updating a DATE column. When I use “Conn.Execute SQLUpdate” (where Conn is my ODBC Connection and SQLUpdate is the update string), it works fine. When I try to use Set RS_Animais = TBAnimais.getAnimais(CNPJ_Fazenda, Codigo, adLockBatchOptimistic) ' the above line calls a routine that returns the line I need to update. I checked ' and there is a valid line. With RS_Animais .Fields("Animais_DtUltimoPesoIndividual") = DtPesagem ‘ if I comment this line, it WORKS!!! .Fields("Animais_UltimoPesoIndividual") = To_MySql(Peso) .Update End With RS_Animais.UpdateBatch 'error occurs here. I tried FormatDateTime(DtPesagem, vbGeneralDate) and vbShortDate but it didn’t work. I’m using adLockBatchOptimistic because I have to update two other tables and the code has the Conn.BeginTrans, Conn.CommitTrans and Conn.RollbackTrans.
View Replies !
Finding Column Total In Specified Date Range
I'm stumped on an issue that I'm hoping someone can shed some light on. I have a table that tracks financial transactions for multiple members with two key fields being 'available' and 'pending' balances. I am trying to write a select query that will allow me to view the total available and pending balances for all members in a specified date range. Essentially what I need to do is select the sum of each balance type from each unique member at the latest point in the given date range. I've been toying with queries like: SELECT id, MAX(available_balance) AS available, MAX(pending_balance) AS pending FROM members.trans_hist WHERE date BETWEEN '$fromDate' AND '$toDate' GROUP BY pt_id"
View Replies !
Selecting Records, Then Summing Parts Of A Column, Then Sorting By That Column...
I’m keeping track of baseball stats, and each row represents one line of stats (from a box score) for one player of a single game. Because of this, a single player may have multiple rows in the table. I want to cumulate each player’s stats (so they’ll be one row per player) and display as output, which isn’t a problem. Then I want sort by a certain stat, but by now I’ve already looped through the table, so I can’t sort using a mySQL query at this point. I tried first putting values into an array in a previous project, but that became extremely complicated. What’s the best way to approach this?
View Replies !
Date/Time As A Default Values For A Table Column
I am new to mySQL, so this question might be simple.I want to add a default value to a column that is the current date/time. I am using the mySQL Administrator and will not allow me to use a function like CURRENT_TIMESTAMP() or NOW() as a default value. I used to do this with other databases (I always add a column to all of my tables called InsertDateTime and UpdateDateTime. It helps to track down data entry problems)
View Replies !
Viewing Date Range Then Adding Column Totals?
this is probably my most complex question to date. Basically i have a table that stores order information for products. What i need to do is: - Specify a Date range - Count number of rows in that range - Get column totals for that range - Return Array with column totals eg, if the array was named $total, $total['column1'] would be the column 1 total :) This is a large table with many columns so here is what i had planned: //OPEN CONNECTION HERE, SET DB //First query gets date range: $result = mysql_query("SELECT * FROM D_Orders_Columbus WHERE odate > '" . $startdate . "' AND odate < '" . $enddate . "'"); //now we get number of rows: $num_orders = mysql_num_rows($result); After that i get stuck, i need it to ADD the column values together, for this i assume i will need to set the column types to 'SMALLINT' (i dont assume anyone will order 32000 items :p). How can i get mysql to total all the columns that can be (eg. have number types) and then return an array with the totals?
View Replies !
Recording The Date A Particular Field Is Updated
I have a table, which has LastUpdated field that records when a record is updated. This is mainly being used to enable the site owner to send out email shots like so : 1. An email address is added to a record, and records the date. 2. At the end of the day, a search is carried out for that date. 3. A list of contacts updated (had an email address added) that day is returned. 4. They click through to a compose email page, which in the background updated an EmailList field fron N to Y. 5. The email is sent to contacts where EmailList=Y. 6. A button at the end resets the EmailList field back to N for the next time its used. Which all works great, but we've had a couple of issues where users haven't quite appreciated what is happening, and have managed to return all contacts in error, update the EmailList for them all to Y, then abort the process midway, without completing the step which resets that field back back to N. So... what I think would resolve this is to have an EmailAddressUpdated field which records when the EmailAddress field is updated, rather than the existing general LastUpdated field which records when the record is updated in any way.
View Replies !
How To Pass A Java.util.Date Object To A DATETIME Column Definition?
I am writing to a MySQL table via JDBC. I have some column definitions with type DATETIME. Here is my table definition: mysql> describe sessions; +-----------------+-------------+------+-----+---------+-------+ | Field | Type | Null | Key | Default | Extra | +-----------------+-------------+------+-----+---------+-------+ | uid | int(11) | | PRI | 0 | | | site_id | varchar(32) | | | | | | session_id | int(11) | | | 0 | | | context | varchar(32) | YES | | NULL | | | create_time | datetime | YES | | NULL | | | expiration_time | datetime | YES | | NULL | | +-----------------+-------------+------+-----+---------+-------+ 6 rows in set (0.00 sec) My statement text is: Code:
View Replies !
Increment Column Without Auto Increment
What's the fastest way I can use an INSERT statement to insert a new record including an 'ID' which is one greater than the current highest ID in the table. Is this possible without first doing a SELECT query? I'll be using php too btw, so if there's a way to do this in php, then I'm open to such suggestions also.
View Replies !
Update Part Of Column Into Another Column
I'm looking for a way to update a SQL column with a portion of info from another column in the same table. example of a sql command -------------------------- UPDATE table1 SET table1.columnname1 = table1.columnname2 FROM table WHERE blah blah blah Here's the thing... I only need a portion of the data found in the source column. I'm not sure how I would do this then. for example, the database has countries and states combined into one column like this 'US-DC', 'US-CA', US-FL', etc. I want to separate these into two columns, a country column and a state column.... and I dont want to go though all the results and do this line by line. How would I write the SQL command so that it puts just the country in the country column, and puts just the state in the state column, and it omits the dash all together. any ideas?
View Replies !
Order By On Column And Reoder By Another Column
im using php and mysql, but i would like from the sql statement to get the results of a query order by a column and then reorder by another column that is: i want to select the last four entries accoding to the date. SELECT * FROM table ORDER BY Date DESC LIMIT 4 but I also want to order those 4 entries i got, according to their values at the order column like this SELECT * FROM table ORDER BY ordercol ASC LIMIT 4 how can i put this two together? i thougt of SELECT * FROM table ORDER BY Date DESC, ordercol ASC LIMIT 4 but it gets the last four entries and then if two entries have the same date it orders them according to the ordercol, how can it do it?
View Replies !
Testing The Updated Database Whether It Is Properly Updated Or Not
After updating the large database with large sets of data (usually from tab delimited files and by programs). How do I check the database whether it is properly updated or not? .Since if there is a subtle error in tab delimited files will lead to improper update of the tables with NULL fields. I have to check the database for NULL fields and whether the updation is complete or broken by some other means(Powercut while updating a huge data).
View Replies !
|