MySQL: Difference between revisions

From Rixort Wiki
Jump to navigation Jump to search
Created page with "== Links == * [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] Category:MySQL"
 
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
== 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
== Links ==
== Links ==


* [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://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

Links