MySQL: Difference between revisions

From Rixort Wiki
Jump to navigation Jump to search
No edit summary
Line 10: Line 10:
   REFERENCED_TABLE_SCHEMA = 'database' AND
   REFERENCED_TABLE_SCHEMA = 'database' AND
   REFERENCED_TABLE_NAME = 'table';
   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 ==

Revision as of 14:28, 10 October 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