You can not use the ALTER TABLE statement to rename a column in SQLite. Then it will insert all of the data (excluding the hire_date field) from the _employees_old table into the employees table. Then it will create the new employees table with the hire_date field removed. This example will rename our existing employees table to _employees_old. SELECT employee_id, last_name, first_name INSERT INTO employees (employee_id, last_name, first_name) Let's look at an example that shows how to drop a column in a SQLite table.įor example, if we had an employees table that was defined as follows: CREATE TABLE employeesĪnd we wanted to drop the column called hire_date, we could do the following: PRAGMA foreign_keys=off The syntax to DROP A COLUMN in a table in SQLite is: PRAGMA foreign_keys=off Instead you will need to rename the table, create a new table, and copy the data into the new table. You can not use the ALTER TABLE statement to drop a column in a table. Then it will insert all of the data from the _employees_old table into the employees table. Then it will create the new employees table with the last_name field defined as a VARCHAR datatype. SELECT employee_id, last_name, first_name, hire_date INSERT INTO employees (employee_id, last_name, first_name, hire_date) ( employee_id INTEGER PRIMARY KEY AUTOINCREMENT,Īnd we wanted to change the datatype of the last_name field to VARCHAR, we could do the following: PRAGMA foreign_keys=off ĪLTER TABLE employees RENAME TO _employees_old Let's look at an example that shows how to modify a column in a SQLite table.įor example, if we had an employees table that had a column called last_name that was defined as a CHAR datatype: CREATE TABLE employees The syntax to MODIFY A COLUMN in a table in SQLite is: PRAGMA foreign_keys=off ĪLTER TABLE table1 RENAME TO _table1_old You can not use the ALTER TABLE statement to modify a column in SQLite.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |