MySQL: Fill field with random dates (quick and dirty)
I had to fill a tablefield with some quick random dates for testing purposes and ran into this little gem:(it fills the field for each record with a random date between January 1 and June 28 2013)...
View ArticleMySQL – How to convert all my tables from MyISAM to InnoDB
While tinkering with XBMC and MySQL, I had to convert a long list of tables from MyISAM to InnoDB. The following query nicely creates all ALTER statements needed to modify all your tables:(replace...
View ArticleMySQL – Show all databases on your MySQL server
Trivial, I know, but I tend to forget this little SQL statement that shows me all databases on my MySQL server: show databases; Output: +--------------------+| Database |+--------------------+|...
View ArticleMySQL – What is my thread or connection ID?
Sometimes a query can go haywire, often I do recognize which of the connections/processes is mine based on the SQL statement that is running, but sometimes it can be hard for example when my query...
View ArticleMySQL – What is the current value of the auto-increment field of my table?
Sometimes you want to know what the next value of an auto increment field will be of a field in your table. A simple query shows you the last used value (add one to know what the next auto increment...
View ArticleMySQL – How to calculate an persons' Age based on a Date (DOB)
Sometimes you need to determine the age of a person, given a data of birth (DOB) … there is no given function in MySQL that can do this, but with the following query you’ll be able to determine a...
View ArticleVBA/MS Access – Determine age based on date of birth (DOB)
Right after posting the trick fo MySQL on how to determine age, I bumped into this VBA function that does the same: This function calculated age based on [Birthdate] and today (Date) and returns the...
View ArticleSQLite – Reset Autoincrement Fields
When flushing tables in SQLite, the auto increment fields can be reset as follows for ALL tables: delete from sqlite_sequence; Or as follow for a specific table: delete from sqlite_sequence where...
View ArticleMySQL – How to detect if a table exists …
A simple query gives you either ‘0’ if the table does not exist, or >0 if the table(s) exist – you can even use a LIKE statement to look for multiple tables: SELECT count(*)FROM...
View ArticleSQLite – Ordering text as numbers …
When trying to sort text as number in SQLite, you’ll run into some issues where it does not sort numerical.With a little trick we can order text numerically, even for fields that start with a number....
View ArticleSQLite – Sort text case insensitive
When you do a ORDER BY a field say “title” which has for example the following values, title----- c a D Z B X then with: SELECT ... ORDER BY title ASC; You’ll get: B D X Z a c To sort this...
View ArticleSQLite – Compact and Optimize your database, using VACUUM, in Lazarus...
A SQLite database can be rebuild (and therefor optimized and defragmented) with the VACUUM SQL statement.Executing this statement requires that you cannot really work with your usual database...
View ArticleMySQL – How to reset Auto Increment fields
In order to reset the auto_increment, in a situation where some of the most recently added rows were deleted, use: ALTER TABLE theTableInQuestion AUTO_INCREMENT=1234 and future insertions will be...
View ArticleSQLite – Natural sort of numeric strings quick and easy
So I ran into the issue that I wanted to sort numbers followed by a character in a natural order.Some examples: “480p”, “720p”, “1080p” These would sort (as strings): 1080p, 480p, 720p with a normal...
View ArticleSQLite – Update multiple rows, with different values, in one query
I ran into a little “problem” where I wanted to updated multiple rows, in SQLite, each with their own “set” of values.I also wanted to avoid running an update query for each row.So how can this be...
View ArticleSQLite – Use COUNT to count rows from multiple tables
In regular SQL, you can count the number of rows in a table with SELECT COUNT(*) FROM Table; Now how would one do this with multiple tables? Below an example by using subqueries, which is pretty...
View ArticleMySQL – What is my thread or connection ID?
Sometimes a query can go haywire, often I do recognize which of the connections/processes is mine based on the SQL statement that is running, but sometimes it can be hard for example when my query...
View ArticleMySQL – What is the current value of the auto-increment field of my table?
Sometimes you want to know what the next value of an auto increment field will be of a field in your table. A simple query shows you the last used value (add one to know what the next auto increment...
View ArticleMySQL – How to calculate an persons' Age based on a Date (DOB)
Sometimes you need to determine the age of a person, given a data of birth (DOB) … there is no given function in MySQL that can do this, but with the following query you’ll be able to determine a...
View ArticleVBA/MS Access – Determine age based on date of birth (DOB)
Right after posting the trick fo MySQL on how to determine age, I bumped into this VBA function that does the same: This function calculated age based on [Birthdate] and today (Date) and returns the...
View Article