修改表結構的寫法

2021-06-19 22:39:30 字數 483 閱讀 1327

1、新增字段

alter table student add age number(5); 

2、修改字段

alter table student modify age number(10);

alter table table2 rename column result to result2;

3、刪除字段

alter table student drop column age;

4、清空表中資料

truncate table student; 

正常情況下刪除資料,如果發現刪除錯了,則可以通過 rollback 回滾。如果使用了截斷表,

則表示所有的資料不可恢復了.所以速度很快(更詳細的說明可檢視 oracle 體系結構)

5、刪除表

drop table student;

6、重新命名表

rename student to student1;

表結構的基類寫法

1在 course models.py寫表結構 from django.db import models class base models.model create time models.datetimefield 建立時間 auto now add true,null true update ...

修改表結構

add column create definition first after column name 新增新字段 add index index name index col name,新增索引名稱 add primary key index col name,新增主鍵名稱 add unique...

修改表結構

1.alter操作表字段 1 增加字段 alter table 表名 add 欄位名 字段型別 alter table student add name varchar 10 2 修改字段 alter table 表名 change 舊欄位名 新欄位名 字段型別 alter table 表名 mod...