Showing posts with label MySQL. Show all posts
Showing posts with label MySQL. Show all posts

Friday, August 22, 2014

How do you execute all sql files in a directory?

my $path = 'C:\TestSQL';

my @scripts = `dir /B /s $path`;

foreach my $sqlfile (@scripts) {
   if ( $sqlfile =~ /^(.+\.sql)\s*$/i ) {
       `mysql <db_name> -u <user_name> -p <password> < $sqlfile.sql`;
   }
}

Tuesday, May 14, 2013

How do you find all the tables with specific column names in MySQL?

SELECT DISTINCT TABLE_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE COLUMN_NAME IN ( 'ColumnA', 'ColumnB' )
AND TABLE_SCHEMA = 'DatabaseName';

Thursday, April 4, 2013