📌  相关文章
📜  sqlite alter table add column - SQL (1)

📅  最后修改于: 2023-12-03 15:20:18.099000             🧑  作者: Mango

SQLite ALTER TABLE ADD COLUMN

SQLite is a popular lightweight relational database management system. One of the most common tasks you'll do with SQLite is modifying existing database tables. This guide will explore how to use the ALTER TABLE command in SQLite to add a new column to a table.

Syntax

The basic syntax for adding a new column to an existing table in SQLite is as follows:

ALTER TABLE table_name
ADD COLUMN column_name data_type;
  • table_name: The name of the table that you want to modify.
  • column_name: The name of the new column that you want to add to the table.
  • data_type: The data type of the new column.
Example

Let's say you have a table called students with the following columns:

  • id: integer primary key autoincrement
  • first_name: text
  • last_name: text
  • age: integer

Now, let's say you want to add a new column called email to this table. Here's how you would do it:

ALTER TABLE students
ADD COLUMN email text;

This command will add a new column called email to the students table with a data type of text.

Conclusion

In this guide, we've learned how to use the ALTER TABLE command in SQLite to add a new column to an existing table. By following the syntax and example provided in this guide, you should be able to easily modify your SQLite tables to meet your needs.