Getting “Lock wait timeout exceeded; try restarting transaction” even though I’m not using a transaction

You are using a transaction; autocommit does not disable transactions, it just makes them automatically commit at the end of the statement. What is happening is, some other thread is holding a record lock on some record (you’re updating every record in the table!) for too long, and your thread is being timed out. You … Read more

How can I get column names from a table in SQL Server?

You can obtain this information and much, much more by querying the Information Schema views. This sample query: Can be made over all these DB objects: CHECK_CONSTRAINTS COLUMN_DOMAIN_USAGE COLUMN_PRIVILEGES COLUMNS CONSTRAINT_COLUMN_USAGE CONSTRAINT_TABLE_USAGE DOMAIN_CONSTRAINTS DOMAINS KEY_COLUMN_USAGE PARAMETERS REFERENTIAL_CONSTRAINTS ROUTINES ROUTINE_COLUMNS SCHEMATA TABLE_CONSTRAINTS TABLE_PRIVILEGES TABLES VIEW_COLUMN_USAGE VIEW_TABLE_USAGE VIEWS

How to group by month from Date field using sql

I would use this: This will group by the first of every month, so will give ‘20130101’. I generally prefer this method as it keeps dates as dates. Alternatively you could use something like this: It really depends what your desired output is. (Closing Year is not necessary in your example, but if the date range … Read more

How can I do ‘insert if not exists’ in MySQL?

Use INSERT IGNORE INTO table. There’s also INSERT … ON DUPLICATE KEY UPDATE syntax, and you can find explanations in 13.2.6.2 INSERT … ON DUPLICATE KEY UPDATE Statement. Post from bogdan.org.ua according to Google’s webcache: 18th October 2007 To start: as of the latest MySQL, syntax presented in the title is not possible. But there are several very easy ways to accomplish … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)