Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Xicheng Guo committed Oct 26, 2024
1 parent ee4d887 commit 0df4a96
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/.vitepress/sidebars/sqlite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,23 @@
- text: 创建数据库
link: /database/sqlite/core-concepts/database-operations#创建数据库
- text: 检查数据库
link: /database/sqlite/core-concepts/database-operations#检查数据库
link: /database/sqlite/core-concepts/database-operations#检查数据库
- text: 数据表操作
link: /database/sqlite/core-concepts/table-operations
items:
- text: 创建表
link: /database/sqlite/core-concepts/table-operations#创建表
- text: 查看表
link: /database/sqlite/core-concepts/table-operations#查看表
- text: 修改表
link: /database/sqlite/core-concepts/table-operations#修改表
items:
- text: 添加列
link: /database/sqlite/core-concepts/table-operations#添加列
- text: 重命名列
link: /database/sqlite/core-concepts/table-operations#重命名列
- text: 删除列
link: /database/sqlite/core-concepts/table-operations#删除列
- text: 删除表
link: /database/sqlite/core-concepts/table-operations#删除表

104 changes: 104 additions & 0 deletions src/database/sqlite/core-concepts/table-operations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
# 数据表操作

## 创建表

::: code-group

```sql [语法]
create table database_name.table_name (
column1 datatype primary key(one or more columns),
column2 datatype,
...
columnN datatype
)
```

```sql [实例]
create table company (
id integer primary key not null,
username text not null,
age integer not null,
salary real
)
```

:::

## 查看表

使用`.tables`命令查看数据库中的所有表。

```bash
sqlite> .tables
company users
```

使用`.schema`命令查看表的结构。

```bash
sqlite> .schema company
CREATE TABLE company (
id integer primary key not null,
username text not null,
age integer not null,
salary real
);
```

## 修改表

### 添加列

::: code-group

```sql [语法]
alter table database_name.table_name add column_name datatype;
```

```sql [实例]
alter table company add email text
```

:::

### 重命名列

::: code-group

```sql [语法]
alter table database_name.table_name rename column_name to new_column_name;
```

```sql [实例]
alter table company rename username to name;
```

:::

### 删除列

::: code-group

```sql [语法]
alter table database_name.table_name drop column column_name;
```

```sql [实例]
alter table company drop column email;
```

:::

## 删除表

::: code-group

```sql [语法]
drop table database_name.table_name
```

```sql [实例]
drop table company;
```

:::

0 comments on commit 0df4a96

Please sign in to comment.