MySQL: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 3: | Line 3: | ||
https://stackoverflow.com/questions/201621/how-do-i-see-all-foreign-keys-to-a-table-or-column | https://stackoverflow.com/questions/201621/how-do-i-see-all-foreign-keys-to-a-table-or-column | ||
SELECT | SELECT | ||
TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME | |||
FROM | FROM | ||
INFORMATION_SCHEMA.KEY_COLUMN_USAGE | |||
WHERE | WHERE | ||
REFERENCED_TABLE_SCHEMA = 'database' AND | |||
REFERENCED_TABLE_NAME = 'table'; | |||
== Update a random selection of rows == | |||
To update approximately 50% of rows: | |||
UPDATE table SET column = 'value' WHERE RAND() < 0.5 | |||
== Links == | == Links == | ||
Line 15: | Line 21: | ||
* [https://github.blog/2016-08-01-gh-ost-github-s-online-migration-tool-for-mysql/ gh-ost: GitHub’s online schema migration tool for MySQL] | * [https://github.blog/2016-08-01-gh-ost-github-s-online-migration-tool-for-mysql/ gh-ost: GitHub’s online schema migration tool for MySQL] | ||
* [https://www.red-gate.com/simple-talk/cloud/cloud-data/designing-highly-scalable-database-architectures/ Designing Highly Scalable Database Architectures] - Not specific to MySQL. | * [https://www.red-gate.com/simple-talk/cloud/cloud-data/designing-highly-scalable-database-architectures/ Designing Highly Scalable Database Architectures] - Not specific to MySQL. | ||
* [https://mariadb.com/kb/en/library/backup-and-restore-overview/ MariaDB: Backup and restore overview] | |||
[[Category:MySQL]] | [[Category:MySQL]] |
Latest revision as of 15:35, 5 December 2019
Show foreign keys for a given table
https://stackoverflow.com/questions/201621/how-do-i-see-all-foreign-keys-to-a-table-or-column
SELECT TABLE_NAME,COLUMN_NAME,CONSTRAINT_NAME, REFERENCED_TABLE_NAME,REFERENCED_COLUMN_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = 'database' AND REFERENCED_TABLE_NAME = 'table';
Update a random selection of rows
To update approximately 50% of rows:
UPDATE table SET column = 'value' WHERE RAND() < 0.5