If your database is connected to an app, you’d probably want to take that app offline or put into some maintenance mode so that any database changes you make don’t effect the application.
Also, BACKUP before making any changes.
You can also rename multiple tables in one go
You can also use the
IF EXISTS keyword (preferred)
The benefit of
IF EXISTS is that it’ll result in a warning instead of an error. The rest of the code will still run after a warning but not after an error.
Truncate deletes a table and then creates a new empty table of the same name.
TRUNCATE keyword doesn’t need to take the
TABLE keyword after it. The following will work just fine.
To make changes to a column, first you’ll specify the table which contains the column with
ALTER TABLE table_name and then you’ll use the keyword
DELETE followed by column name and values.
COLUMN is an optional keyword, only
ADD will also work. Here’s another example
CHANGE can not take multiple columns. For every column name you want to change, you’ll have to create a new statement.
Change Data Type
Determing a Column’s place
You can determine where to add a column using the keywords
will add a column name and add it as the
FIRST column of the table. Similarly, the code below will add the column name
AFTER the column id
Here is another example
IF EXISTS when dropping a database which doesn’t exist will return in a warning instead of an error, meaning the subsequent SQL commands will still run. Using
IF EXISTS will keep your script running and avoid errors.