Remove Primary Key in MySQL

Without an index, maintaining an autoincrement column becomes too expensive, that’s why MySQL requires an autoincrement column to be a leftmost part of an index. You should remove the autoincrement property before dropping the key: ALTER TABLE user_customer_permission MODIFY id INT NOT NULL; ALTER TABLE user_customer_permission DROP PRIMARY KEY; Note that you have a composite … Read more

postgresql list and order tables by size

select table_name, pg_relation_size(quote_ident(table_name)) from information_schema.tables where table_schema=”public” order by 2 This shows you the size of all tables in the schema public if you have multiple schemas, you might want to use: select table_schema, table_name, pg_relation_size(‘”‘||table_schema||'”.”‘||table_name||'”‘) from information_schema.tables order by 3 SQLFiddle example: http://sqlfiddle.com/#!15/13157/3 List of all object size functions in the manual.

OPTION (RECOMPILE) is Always Faster; Why?

There are times that using OPTION(RECOMPILE) makes sense. In my experience the only time this is a viable option is when you are using dynamic SQL. Before you explore whether this makes sense in your situation I would recommend rebuilding your statistics. This can be done by running the following: EXEC sp_updatestats And then recreating … Read more

Set NOW() as Default Value for datetime datatype?

As of MySQL 5.6.5, you can use the DATETIME type with a dynamic default value: CREATE TABLE foo ( creation_time DATETIME DEFAULT CURRENT_TIMESTAMP, modification_time DATETIME ON UPDATE CURRENT_TIMESTAMP ) Or even combine both rules: modification_time DATETIME DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP Reference: http://dev.mysql.com/doc/refman/5.7/en/timestamp-initialization.html http://optimize-this.blogspot.com/2012/04/datetime-default-now-finally-available.html Prior to 5.6.5, you need to use the TIMESTAMP data type, … Read more

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