SQLite ALTER TABLE order alters a current table without playing out a full dump and reload of the information. You can rename a table utilizing ALTER TABLE explanation and extra sections can be included a current table utilizing ALTER TABLE articulation.
There is no other activity upheld by ALTER TABLE order in SQLite aside from renaming a table and adding a segment in a current table.
Syntax
Following is the fundamental grammar of ALTER TABLE to RENAME a current table.
ALTER TABLE database_name.table_name RENAME TO new_table_name;
Following is the fundamental grammar of ALTER TABLE to add another segment in a current table.
ALTER TABLE database_name.table_name ADD COLUMN column_def...;
Example
Consider the COMPANY table with the accompanying records −
ID NAME AGE ADDRESS SALARY
---------- ---------- ---------- ---------- ----------
1 Paul 32 California 20000.0
2 Allen 25 Texas 15000.0
3 Teddy 23 Norway 20000.0
4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
6 Kim 22 South-Hall 45000.0
7 James 24 Houston 10000.0
Presently, we should attempt to rename this table utilizing ALTER TABLE explanation as follows −
sqlite> ALTER TABLE COMPANY RENAME TO OLD_COMPANY;
The above SQLite proclamation will rename COMPANY table to OLD_COMPANY. Presently, how about we attempt to add another section in OLD_COMPANY table as follows −
sqlite> ALTER TABLE OLD_COMPANY ADD COLUMN SEX char(1);
Organization table is presently changed and following will be the yield from SELECT proclamation.
ID NAME AGE ADDRESS SALARY SEX
---------- ---------- ---------- ---------- ---------- ---
1 Paul 32 California 20000.0
2 Allen 25 Texas 15000.0
3 Teddy 23 Norway 20000.0
4 Mark 25 Rich-Mond 65000.0
5 David 27 Texas 85000.0
6 Kim 22 South-Hall 45000.0
7 James 24 Houston 10000.0
It ought to be noticed that recently added section is loaded up with NULL qualities.