📅  最后修改于: 2023-12-03 15:20:18.099000             🧑  作者: Mango
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.
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.Let's say you have a table called students
with the following columns:
id
: integer primary key autoincrementfirst_name
: textlast_name
: textage
: integerNow, 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
.
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.