![]() If the new column is a foreign key and the foreign key constraint check is enabled, the new column must accept a default value NULL.įor example, you can add a new column named location to the equipment table: ALTER TABLE equipmentĪDD COLUMN location text Code language: SQL (Structured Query Language) ( sql ).The new column cannot have a default of CURRENT_TIMESTAMP, CURRENT_DATE, and CURRENT_TIME, or an expression.If the new column has a NOT NULL constraint, you must specify a default value for the column other than a NULL value.The new column cannot have a UNIQUE or PRIMARY KEY constraint. ![]() There are some restrictions on the new column: The following illustrates the syntax of ALTER TABLE ADD COLUMN statement: ALTER TABLE table_nameĪDD COLUMN column_definition Code language: SQL (Structured Query Language) ( sql ) In this scenario, SQLite appends the new column at the end of the existing column list. ![]() You can use the SQLite ALTER TABLE statement to add a new column to an existing table. Try It Using SQLite ALTER TABLE to add a new column to a table SELECT name,Įquipment Code language: SQL (Structured Query Language) ( sql ) Third, query data from the equipment table to verify the RENAME operation. RENAME TO equipment Code language: SQL (Structured Query Language) ( sql ) Second, use the ALTER TABLE RENAME TO statement to change the devices table to equipment table as follows: ALTER TABLE devices VALUES( 'HP ZBook 17 G3 Mobile Workstation', 'ZBook', 'SN-2015') Code language: SQL (Structured Query Language) ( sql ) INSERT INTO devices ( name, model, serial) Let’s take an example of renaming a table.įirst, create a table named devices that has three columns: name, model, serial and insert a new row into the devices table.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |