I have a table with a column 'search_text' type text.
In that field I have values:
1. 'MyBook MyBook PDF PDF',
2. 'Example 1 Example 2 Example 3'
3. 'John Snow John Snow'
I would like to distinct clean these fields.
Expected result:
1. 'MyBook PDF',
2. 'Example 1 2 3'
3. 'John Snow'
The approach I came up with goes as follows:
read the field for each record, split it by space (' '), put each text in array, do array_unique in PHP, then put the array back to string with join in PHP.
The thing is, this is a PHP based solution, I would like to have an MySQL solution for this. I have over 180.000 records I need to clean, I don't know what impact it would have to run this on PHP.
I have found a solution for MS SQL: Remove duplicate values in a cell SQL Server
Help greatly appreciated.
SQL of my test data:
CREATE TABLE IF NOT EXISTS `test` (
`id` int(10) unsigned NOT NULL,
`search_text` text COLLATE utf8_unicode_ci NOT NULL
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
INSERT INTO `test` (`id`, `search_text`) VALUES
(1, 'MyBook MyBook PDF PDF'),
(2, 'Example 1 Example 2 Example 3'),
(3, 'John Snow John Snow'),
(4, 'test test test test formula test test test formula test test test formula test test test formula test test test formula test test test formula '),
(5, '');
ALTER TABLE `test`
ADD PRIMARY KEY (`id`);
ALTER TABLE `test`
MODIFY `id` int(10) unsigned NOT NULL AUTO_INCREMENT,AUTO_INCREMENT=6;
Try this to sort by count :)
SELECT DISTINCT SUBSTRING_INDEX(SUBSTRING_INDEX(test.search_text, ' ', numbers.n), ' ', - 1) col_name
FROM (
SELECT 1 n
UNION ALL
SELECT 2
UNION ALL
SELECT 3
UNION ALL
SELECT 4
) numbers
INNER JOIN test ON CHAR_LENGTH(test.search_text) - CHAR_LENGTH(REPLACE(test.search_text, ' ', '')) >= numbers.n - 1
ORDER BY col_name;
You will need to write a MySQL function to do this for you. I would think that a PHP page will be just fine. 180,000 records isn't that many and it should (unless you are using a low spec server) run without putting much strain on anything else.
I wrote 2 for you that you might be able to make use of:
DROP PROCEDURE IF EXISTS explode;
DELIMITER //
CREATE PROCEDURE explode(str_string TEXT)
NOT DETERMINISTIC
BEGIN
DROP TABLE IF EXISTS explosion;
CREATE TABLE explosion (id INT AUTO_INCREMENT PRIMARY KEY NOT NULL, word VARCHAR(100));
SET #sql := CONCAT('INSERT INTO explosion (word) VALUES (', REPLACE(QUOTE(str_string), " ", '\'), (\''), ')');
PREPARE myStmt FROM #sql;
EXECUTE myStmt;
END //
DELIMITER ;
This procedure creates an "explode" function for use in MySQL. It uses a temporary table and explodes the words, separated by spaces into it
Then this function will read that table in, and put them into another temporary table with the duplicates removed:
DROP PROCEDURE IF EXISTS removeDuplicates;
DELIMITER //
CREATE PROCEDURE removeDuplicates(str TEXT)
BEGIN
DECLARE temp_word TEXT;
DECLARE last_word TEXT DEFAULT "";
DECLARE result TEXT;
DECLARE finished INT DEFAULT false;
DECLARE words_cursor CURSOR FOR
SELECT word FROM explosion;
DECLARE CONTINUE handler FOR NOT found
SET finished = true;
CALL explode(str);
DROP TABLE IF EXISTS temp_words;
CREATE TABLE temp_words (id INT AUTO_INCREMENT PRIMARY KEY NOT NULL, t VARCHAR(100));
OPEN words_cursor;
loop_words: LOOP
FETCH words_cursor INTO temp_word;
IF finished THEN
LEAVE loop_words;
END IF;
IF last_word = "" THEN
INSERT INTO temp_words (t) VALUES (temp_word);
SET last_word = temp_word;
ITERATE loop_words;
END IF;
IF last_word = temp_word THEN
SET last_word = temp_word;
ITERATE loop_words;
END IF;
INSERT INTO temp_words (t) VALUES (temp_word);
END LOOP loop_words;
CLOSE words_cursor;
END //
DELIMITER ;
So all you need to do is work out how to get the records in temp_words into your current database table.
I went for the PHP solution here:
$s = 'John Snow John Snow';
//remove duplicate values in string
$tmpArray = explode(" ", $s);
$tmpArray = array_unique($tmpArray);
$s = join(" ", $tmpArray);
Which is run before INSERT, and it does what I wanted.
Related
$link->query("DROP TABLE IF EXISTS table2");
$link->query("CREATE TABLE table2 (newcol BIGINT UNSIGNED PRIMARY KEY)");
$result=$link->query("select col1 from table1");
while($data=$result->fetch_array(MYSQL_ASSOC))
{
$link->query("insert into table2 (newcol) values($data['col1']);
$link->query(""ALTER TABLE table2 ADD `".$data['col1']."` BIGINT DEFAULT 0"");
}
What Iam trying to do is
Create a table "table2" with one column "newcol".
select all the values of "col1" from "table1" And
for each value of col1 from table1
-insert the value into "newcol" of table2 And
-add a column named (value from col1 of table 1) into "table2"
The above code looks very neat and efficient in php , but the problem is it takes some amount of time .So I think its better to convert these into MySQL Stored procedure .Since I'm new to stored procedures , very much confused .Please help me guys.
Of course, I couldn't test it, but it is compiling fine on on my computer.
DELIMITER //
CREATE PROCEDURE `myProcedure` ()
BEGIN
DECLARE _done BOOLEAN DEFAULT FALSE;
DECLARE _myField BIGINT UNSIGNED DEFAULT 0;
/* the cursor here is like your PDOStatement
* it is used to fetch data */
DEClARE _myReader CURSOR FOR
SELECT `col1` FROM `table1`;
/* it is not very elegant, but we need to throw an exception
* to break the loop */
DECLARE CONTINUE HANDLER
FOR NOT FOUND SET _done = TRUE;
DROP TABLE IF EXISTS `table2`;
CREATE TABLE `table2` (
`newcol` BIGINT UNSIGNED PRIMARY KEY
);
/* you open your PDOStatement */
OPEN _myReader;
/* myLoop is like a GOTO*/
myLoop: LOOP
/* $result->fetch_array(MYSQL_ASSOC)*/
FETCH _myReader INTO _myField;
/* if the no data exception had been thrown,
* goto the end of the loop */
IF _done = 1 THEN
LEAVE myLoop;
END IF;
INSERT INTO `table2` (newcol) VALUES (_myField);
ALTER TABLE `table2` ADD `_myField` BIGINT DEFAULT 0;
END LOOP myLoop;
/* close your PDO object */
CLOSE _myReader;
END //
Jonathan Parent Lévesque helped me a lot in figuring out how the looping inside stored procedures work and to get the overall structure for the stored procedure equivalent to the php code described in the question above.
Thanks Jonathan Parent Lévesque
But in his code Adding column name using a variable didn't work as expected.
Finally I figured it out
BEGIN
DECLARE _done BOOLEAN DEFAULT FALSE;
DECLARE _myField BIGINT DEFAULT 0;
DEClARE _myReader CURSOR FOR
SELECT id FROM `tags`;
DECLARE CONTINUE HANDLER
FOR NOT FOUND SET _done = TRUE;
DROP TABLE IF EXISTS `tag_similarity`;
CREATE TABLE `tag_similarity` (
`tag` BIGINT UNSIGNED PRIMARY KEY
);
OPEN _myReader;
myLoop: LOOP
FETCH _myReader INTO _myField;
IF _done = 1 THEN
LEAVE myLoop;
END IF;
INSERT INTO `tag_similarity` (tag) VALUES (_myField);
SET #sql = CONCAT('ALTER TABLE tag_similarity ADD `',_myfield,'` BIGINT DEFAULT 0');
PREPARE stmt FROM #sql;
EXECUTE stmt ;
DEALLOCATE PREPARE stmt;
END LOOP myLoop;
CLOSE _myReader;
END
Can anybody help me to get the sub_cat(csv) values which are not in id column from same table.
(sub_cat) comma separated values are the ids of same table, i need to get the values which are not in id column. Like 2,3,7 are present in id column whereas 20,24 are not. I need to get 20,24 only.
As I have elaborated in this post, I recommend not storing data in CSV format.
This gives trouble accessing and updating it.
I am not sure about this, but you might be able to simply use:
SELECT sub_cat FROM table_name WHERE id NOT IN (
SELECT sub_cat FROM table_name
)
However, I always prefer to store only one ID per row.
To do this purely in MySQL required writing a stored procedure; you'll need to change the database name test to the actual name of your database. It would have been a whole lot easier to do it with PHP - but where's the fun in that?
DELIMITER //
CREATE PROCEDURE test.check_subcats(
IN s_delimiter VARCHAR(30)
)
DETERMINISTIC
READS SQL DATA
BEGIN
DECLARE s_csv TEXT;
DECLARE i_subcat_index INT(10) unsigned DEFAULT 1;
DECLARE i_subcat_count INT(10) unsigned;
DECLARE l_category_done INT(10) DEFAULT FALSE;
DECLARE c_category CURSOR FOR SELECT category.sub_cat FROM category;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET l_category_done = TRUE;
-- create a temporary table to hold every csv value
CREATE TEMPORARY TABLE IF NOT EXISTS tmp_csv( cvalue VARCHAR(10) NOT NULL );
OPEN c_category;
l_category: LOOP
FETCH c_category INTO s_csv;
IF l_category_done THEN
LEAVE l_category;
ELSE
-- determine the number of sub-categories
SELECT (LENGTH(s_csv) - LENGTH(REPLACE(s_csv, s_delimiter, ''))) + 1 INTO i_subcat_count;
-- loop to store all csv values
WHILE i_subcat_index <= i_subcat_count DO
INSERT INTO tmp_csv ( cvalue ) (
SELECT REPLACE(SUBSTRING(
SUBSTRING_INDEX(s_csv, s_delimiter, i_subcat_index),
LENGTH(SUBSTRING_INDEX(s_csv, s_delimiter, i_subcat_index - 1)) + 1
), s_delimiter, '')
);
SET i_subcat_index = i_subcat_index + 1;
END WHILE;
END IF;
SET i_subcat_index = 1;
END LOOP;
CLOSE c_category;
SELECT DISTINCT tmp_csv.cvalue FROM tmp_csv WHERE tmp_csv.cvalue NOT IN ( SELECT category.id FROM category );
DROP TEMPORARY TABLE IF EXISTS tmp_csv;
END //
DELIMITER ;
I'm not 100% certain as to how robust it is but it was working with your data on my dev box.
You specify the delimiter for your CSV data when you call the procedure thus:
CALL `check_subcats`(',');
Essentially this loops through the category table to read sub_cat. It then splits the sub_cat value into chunks using the delimiter provided (much like PHPs explode() function) and writes every one of those values to a temporary table.
This then gives you a temporary table holding all your CSV data in individual bits and it's then a simple matter of selecting everything from that data that's NOT IN the category.id list.
I've been recently stuck on an issue I've been having involving sending a string of comma separated values into a stored procedure. My issue is that when I execute my stored procedure in PHP it uploads the values with quotes around it like so;
CALL `rankingInformation`('145', '5', '', '37,38,39,40,41')
Failing to add the quotes would make MySQL interpret them as extra parameters.
However it's mean't to be like in the WHERE IN on the query side it's meant to be formatted like so
'37', '38', '39', '40', '41'
Here is the query below, can anyone spot anything I can do? Here is what I've got up to now.
CREATE DEFINER = `root`#` localhost` PROCEDURE` rankingInformation`(IN` surveyId` INT, IN` filterCounting` INT, IN` survey_filter_id` INT, IN` question_limit` TEXT)
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT 'Gathers all the ranking information for a given ID'
BEGIN
DECLARE sfi int(2);
DECLARE ql TEXT;
IF(survey_filter_id = '') THEN
SET sfi = (SELECT sf2.survey_filter_id FROM survey_filters AS sf2 WHERE sf2.survey_id = 145 AND sf2.survey_filter_id IS NOT NULL LIMIT 1);
ELSE
SET sfi = survey_filter_id;
END IF;
SELECT
COUNT( * ) AS total, CONCAT(su.first_name, ' ', su.last_name) as full_name, sf.survey_filter_id, sf.survey_filter_name, qa.question_id, su.temp_group_1 AS department
FROM questions_answers AS qa
INNER JOIN survey_users AS su ON su.survey_users_id = qa.survey_users_id_answer
INNER JOIN survey_filters AS sf ON sf.survey_id = surveyId
WHERE qa.survey_id = surveyId
AND qa.question_id IN (splitAndTranslate(question_limit, ','))
AND sf.survey_filter_id = sfi
GROUP BY qa.survey_users_id_answer
HAVING total > filterCounting
ORDER BY total DESC;
END
splitAndTranslate
Here is a function I found which is mean't to do the job, I am not sure I am far away.
CREATE DEFINER=`root`#`localhost` FUNCTION `splitAndTranslate`(`str` TEXT, `delim` VARCHAR(1))
RETURNS text CHARSET utf8
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT 'Fixes all Where IN issues'
BEGIN
DECLARE i INT DEFAULT 0; -- total number of delimiters
DECLARE ctr INT DEFAULT 0; -- counter for the loop
DECLARE str_len INT; -- string length,self explanatory
DECLARE out_str text DEFAULT ''; -- return string holder
DECLARE temp_str text DEFAULT ''; -- temporary string holder
DECLARE temp_val VARCHAR(255) DEFAULT ''; -- temporary string holder for query
-- get length
SET str_len=LENGTH(str);
SET i = (LENGTH(str)-LENGTH(REPLACE(str, delim, '')))/LENGTH(delim) + 1;
-- get total number delimeters and add 1
-- add 1 since total separated values are 1 more than the number of delimiters
-- start of while loop
WHILE(ctr<i) DO
-- add 1 to the counter, which will also be used to get the value of the string
SET ctr=ctr+1;
-- get value separated by delimiter using ctr as the index
SET temp_str = REPLACE(SUBSTRING(SUBSTRING_INDEX(str, delim, ctr), LENGTH(SUBSTRING_INDEX(str, delim,ctr - 1)) + 1), delim, '');
-- query real value and insert into temporary value holder, temp_str contains the exploded ID
#SELECT ImageFileName INTO temp_val FROM custombu_roomassets_images WHERE ImageID=temp_str;
-- concat real value into output string separated by delimiter
SET out_str=CONCAT(out_str, temp_val, ',');
END WHILE;
-- end of while loop
-- trim delimiter from end of string
SET out_str=TRIM(TRAILING delim FROM out_str);
RETURN(out_str); -- return
END
What did you do with FIND_IN_SET? Building on spencer7593's answer, it should work if you replace:
AND qa.question_id IN (splitAndTranslate(question_limit, ','))
with
AND FIND_IN_SET(qa.question_id, question_limit)>0
The commas within a string value are not interpreted as SQL text in the context of a SQL IN comparison. Your query is essentially of the form:
AND qa.question_id IN ('some,long,string,value')
And any comma characters within the string are just data; just characters that are part of the string. This is effectively the same as an equals comparison.
The MySQL FIND_IN_SET function might be a way for you to perform the comparison you want.
http://dev.mysql.com/doc/refman/5.5/en/string-functions.html#function_find-in-set
AND qa.question_id IN (splitAndTranslate(question_limit, ','))
Put these lines instead of the above line
AND (qa.question_id = question_limit
OR qa.question_id LIKE CONCAT(question_limit,',%')
OR qa.question_id LIKE CONCAT('%,',question_limit,',%')
OR qa.question_id LIKE CONCAT('%,',question_limit))
Then you don't need the splitAndTranslate Function anymore . .
I have below data in Mysql Column (storing all data in serialize form - with comma separated into column) and i want to get/fetch this column data in Mysql stored procedure and want to loop for each data and insert into another trans table.
So if my data like below then i want to insert 7 record in trans table.
{"FormBuilderId":"5","vAnswer":"Develeop"},
{"FormBuilderId":"15","vAnswer":"Search Engine"},
{"FormBuilderId":"13","vAnswer":"10-15"},
{"FormBuilderId":"6","vAnswer":"Tester entered"},
{"FormBuilderId":"1","vAnswer":"Female"},
{"FormBuilderId":"14","vAnswer":"Moon.jpg"},
{"FormBuilderId":"12","vAnswer":"TV,dancing and modeling"}
My table structure & data is like below in table:
CREATE TABLE IF NOT EXISTS `idea_history` (
`iIdeaHistoryId` int(11) NOT NULL AUTO_INCREMENT,
`iApplicationId` tinyint(11) unsigned DEFAULT '0',
`tAnswerData` text COMMENT 'all answer data store here in json format',
`dAddedDate` datetime NOT NULL,
PRIMARY KEY (`iIdeaHistoryId`),
KEY `iApplicationId` (`iApplicationId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='history comes here' AUTO_INCREMENT=57 ;
--
-- Dumping data for table `idea_history`
--
INSERT INTO idea_history (
iIdeaHistoryId,
iApplicationId,
tAnswerData,
dAddedDate
)
VALUES
(
53,
2,
'{"FormBuilderId" : "2","vAnswer":"Environmental Group"},{"FormBuilderId" : "11","vAnswer":"Satelite"},{"FormBuilderId" : "3","vAnswer":"HB"},{"FormBuilderId" : "4","vAnswer":"Dev"},{"FormBuilderId" : "7","vAnswer":"HB"},{"FormBuilderId" : "8","vAnswer":"Balaji Satellite"},{"FormBuilderId" : "10","vAnswer":""}',
'2014-07-05 19:20:56'
),
(
54,
1,
'{"FormBuilderId":"5","vAnswer":"Hello krishna|kanth double"},{"FormBuilderId":"15","vAnswer":"Website"},{"FormBuilderId":"6","vAnswer":"need to check"},{"FormBuilderId":"13","vAnswer":"20-25"}',
'2014-07-05 19:20:56'
),
(
55,
2,
'{"FormBuilderId":"11","vAnswer":"comapnay"},{"FormBuilderId":"8","vAnswer":"here am|chw "},{"FormBuilderId" : "10","vAnswer":""},{"FormBuilderId":"9","vAnswer":"Business"}',
'2014-07-05 19:20:56'
) ;
I will pass iIdeaHistoryId in stored procedure and it will fetch value of tAnswerData field and part this value and insert into another trans table.
Could you please guide what i have to change in stored procedure ?
you can do it like this
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(your_variable,'{"',-1),'":"',1) INTO arg_1;
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(your_variable,'":"',-2),'","',1) INTO arg_2;
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(your_variable,'","',-1),'":"',1) INTO arg_3;
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(your_variable,'":"',-1),'"}',1) INTO arg_4;
INSERT INTO trans VALUES (arg_1,arg_2,arg_3,arg_4);
or if you want to do it in store procedure add your data here
DELIMITER $$
DROP PROCEDURE IF EXISTS trans$$
CREATE PROCEDURE trans()
BEGIN
DECLARE arg_1,arg_2,arg_3,arg_4 VARCHAR(100);
DECLARE finished INTEGER DEFAULT 0;
DECLARE cursor_name CURSOR FOR YOUR_SELECT_statement;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET finished = 1;
OPEN cursor_name;
my_loop: LOOP
FETCH cursor_name INTO your_variable;
IF finished = 1 THEN
LEAVE my_loop;
END IF;
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(your_variable,'{"',-1),'":"',1)
INTO arg_1 FROM your_table;
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(your_variable,'":"',-2),'","',1)
INTO arg_2 FROM your_table;
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(your_variable,'","',-1),'":"',1)
INTO arg_3 FROM your_table;
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(your_variable,'":"',-1),'"}',1)
INTO arg_4 FROM your_table;
INSERT INTO trans VALUES (arg_1,arg_2,arg_3,arg_4);
END LOOP my_loop;
CLOSE cursor_name;
END$$
DELIMITER ;
for one column you use this
DELIMITER $$
DROP PROCEDURE IF EXISTS trans$$
CREATE PROCEDURE trans(IN in_iIdeaHistoryId INT)
BEGIN
DECLARE arg_1 VARCHAR(100);
SELECT SUBSTRING_INDEX(SUBSTRING_INDEX(REPLACE(`tAnswerData`,' ',''),'{"',-1),'":"',1)
INTO arg_1 FROM `idea_history` WHERE iIdeaHistoryId=in_iIdeaHistoryId;
INSERT INTO trans VALUES (arg_1);
END$$
DELIMITER ;
and call it like this
CALL `trans`(53);
This looks like JSON. Use php function json_decode() to store the json data into an array and then you can use foreach loop on that array. Inside the loop you can place condition and when its met, you could use insert query to store it in your database.
Does this help you?
If you can explain a bit further what you're trying to do exactly and what are your condition, then i Can probably give you a better answer.
I have a PHP script where users create questionnaires, and the script tables in the DB to store the incoming data. The site's been live for a while, and there are about 100 tables in the database.
My script was awfully flawed! It calls for "tinytext" fields in places where I really need "text". Is there a way to bulk update all of the tinytext columns to text?
Thanks!
Solution without stored procedures (using only phpMyAdmin or any other DBA tool).
Run the following query
SELECT
CONCAT('ALTER TABLE ',
TABLE_NAME,
' CHANGE COLUMN ',
COLUMN_NAME,
' ',
column_name,
' TARGET_TYPE ',
CASE
WHEN IS_NULLABLE = 'NO' THEN ' NOT '
ELSE ''
END,
' NULL;') AS que
FROM
information_schema.columns
WHERE
table_schema = 'MY DB'
AND data_type = 'SOURCE_TYPE';
This query will return you all the statements to fire. You can run them or save into a SQL Upgrade script
Example (from tinyint to bit):
ALTER TABLE mytable CHANGE COLUMN redacted redacted BIT NULL;
ALTER TABLE mytable CHANGE COLUMN redacted2 redacted2 BIT NOT NULL;
One way of doing this, is to find all the tinytext columns in the given database and then create ALTER TABLE statement for the each column. Working solution using stored procedure:
DELIMITER $$
DROP PROCEDURE IF EXISTS `BULK_RETYPE` $$
CREATE PROCEDURE `BULK_RETYPE`(IN SCHEMA_NAME VARCHAR(255), IN FROM_TYPE VARCHAR(255), IN TO_TYPE VARCHAR(255))
BEGIN
DECLARE `done` INT DEFAULT FALSE;
DECLARE tn VARCHAR(255);
DECLARE fn VARCHAR(255);
DECLARE `cur1` CURSOR FOR
SELECT
`TABLE_NAME`,
`COLUMN_NAME`
FROM
`information_schema`.`COLUMNS`
WHERE
`DATA_TYPE` = FROM_TYPE AND `TABLE_SCHEMA` = SCHEMA_NAME;
DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
OPEN cur1;
read_loop: LOOP
FETCH cur1 INTO `tn`, `fn`;
IF done THEN
LEAVE read_loop;
END IF;
SET #ALTER_SQL = CONCAT('ALTER TABLE ', '`', tn,'`' , ' MODIFY ', '`', fn,'`' , ' ', TO_TYPE);
PREPARE stmt1 FROM #ALTER_SQL;
EXECUTE stmt1;
END LOOP;
CLOSE cur1;
END $$
DELIMITER ;
CALL BULK_RETYPE('test', 'tinytext', 'text');
Not really, though if you use PHPMyAdmin, it's a rather quick task... alternatively, you could export a list of all the tables and fields you need to change and put together the necessary ALTER TABLE statements and then execute them.
You can just select from schema and prepare SQL for mass alter
SELECT table_scheme, table_name, columun_name FROM information_schema.`COLUMNS`
WHERE DATA_TYPE='tinyint'