Skip to content
Advertisement

How to automatically convert a MySQL column to lowercase

Is there a property that I can add to a column so that it converts its value to lowercase? Instead of doing it for every single value through PHP? Answer You could probably do it through a trigger that fires on insert or update. Myself, I’d rather just create a view that has a lower-case version of the column in

MySQL OPTIMIZE all tables?

MySQL has an OPTIMIZE TABLE command which can be used to reclaim unused space in a MySQL install. Is there a way (built-in command or common stored procedure) to run this optimization for every table in the database and/or server install, or is this something you’d have to script up yourself? Answer You can use mysqlcheck to do this at

SQL – Get Numerical Day of Month/Quarter

Using SQL Server 2005: How can I get the numerical day of the month and day of the quarter in a query? DECLARE @DATE DATETIME SET @DATE = GETDATE() SELECT DATEPART(dy, @DATE) AS DayOfYear –, &…

SQL query for today’s date minus two months

I want to select all the records in a table where their date of entry is older then 2 months. Any idea how I can do that? I haven’t tried anything yet but I am on this point: Answer If you are using SQL Server try this: Based on your update it would be:

SQL grouping by month and year

I’m not sure what should I write in the following SQL query to show ‘date’ column like this: “month-year” – “9-2011”. So, what I want to do is to change the data from the first column to show month and year instead of showing month only. Answer Or as @40-Love mentioned you can cast with leading zeroes:

Advertisement