
With this procedure defined, one need only CALL dropMatchingColumns('test\_%') in order to drop all the columns prefixed with test_ from the current database. If a table contains only one column, the column cannot be dropped. A standard for DELETE FROM table WHERE id NOT IN would look like this: DELETE from TableA WHERE id - ID of TableA not in (select ID FROM TableB) This should find the IDs not in Table A from Table B, as your question states. To add a column at a specific position within a table row, use FIRST or AFTER colname. DROP colname is a MySQL extension to standard SQL. WHERE COLUMN_NAME LIKE pattern AND TABLE_SCHEMA = DATABASE()ĭECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE Use ADD to add new columns to a table, and DROP to remove existing columns. For a complete reference of all the data. The data type specifies what type of data the column can hold. delete from table name where column name like text to find This will match if the text appears, regardless of position. ADD DateOfBirth date Notice that the new column, 'DateOfBirth', is of type date and is going to hold a date. We use the following SQL statement: ALTER TABLE Persons. the position of the new column like other database systems such as MySQL. Now we want to add a column named 'DateOfBirth' in the 'Persons' table. 'ALTER TABLE `', REPLACE( TABLE_NAME, '`', '``'), '` ', the Oracle ALTER TABLE ADD column statement to add one or more columns to.

(Most database folks don't routinely drop columns from a database in production it takes a lot of time during which the tables are inaccessible, and it's destructive. You need to generate a list of SQL statements and then run them, somehow. Whilst it is possible to do that within a MySQL stored procedure using SQL prepared statements, which I demonstrate below, you may well find it easier to implement/understand in your preferred development language (which you do not mention in your question): DELIMITER ĬREATE PROCEDURE dropMatchingColumns(IN pattern VARCHAR(64)) 1 Answer Sorted by: 1 There isn't a simple magical expression to just do this. If you actually want to drop the columns from your schema, you will need to generate the necessary SQL commands dynamically from MySQL's information schema tables. 2 I am trying to execute a MySQL query to delete rows from 'table2' where column 'value' IF column in 'table1' 'value' I have 2 tables.
