建立與管理資料表

2021-10-09 21:15:07 字數 1804 閱讀 1427

create table [if not exists]

(列名 資料型別 [not null|null][default 列預設值])

ebgine=儲存引擎

例項
alter table xs add 獎學金等級 char(10) after 總學分; 

alter table xs modify 姓名 char(20);

alter table xs modify 性別 char(1);

alter table xs drop 備註;

alter table xs modify 總學分 char after **;

alter table xs rename to student;

alter table student change 出生時間 出生日期 date;

select * from student;

select * from kc;

alter table kc modify 課程號 int(10);

alter table kc add 總學時 int(10) after 學時;

alter table kc add 任課教師 char(20);

alter table kc modify 開課學期 char after 學分;

alter table kc modify 課程名 char(20);

create table kc_copy like kc;

drop table kc;

use xscj;

show tables;

alter table xs—kc rename xs_kc;

show tables;

desc xs_kc;

create table bj_copy2 as (select * from xs_kc);

desc student;

select 學號 from student;

alter table xs_kc rename 選課表;

alter table 選課表 modify 學號 int(10);

alter table 選課表 add 課程號 char(3) after 課程名;

desc 選課表;

drop table kc_copy;

1.新增列
alter table 表名 add 新列名 first or after  舊列名;
2.對列重新命名
alter table 表名 change 舊列名 新列名的定義;
3.修改列型別

本語句可修改列的型別,同時可以改變列的位置

alter 表名 modify 目標列名的列定義  after or first 參照物列名 ;
4.刪除列名
alter 表名 drop 列名;
5.重新命名表名
alter 原始表名  rename 新錶名;
6.修改預設值
alter table 表名 alter column 欄位名 drop default; (若本身存在預設值,則先刪除)

alter table 表名 alter column 欄位名 set default 預設值;(若本身不存在則可以直接設定)

7.複製表
1.create table 新錶名 link 參照表名;

2.create table 新錶名 (select * from 參照表名);

資料表的建立與管理

實驗01 資料表的建立與管理 實驗內容 1.資料表的建立 建立 使用者表 users create table users username varchar 20 identity 1,1 primary key,userpassword varchar 6 user char 2 userreal...

資料表的建立與管理

在資料庫中通過資料表來存放記錄,在資料表中常常會碰到主外來鍵。索引。約束等條件,以下就具體一下。主鍵 一張資料表中唯一的標識。確保一張資料表中不會出現兩個全然同樣的資料記錄。主鍵能夠定義在多個列上。也就是說在定義資料庫的時候能夠將資料表中的多個列合併在一起作為該錶的主鍵 外來鍵 用來表與表之間關係的...

建立資料表

語法 create table 表名 欄位名稱 字段型別 字段特徵 是否為null,預設值 標識列 主鍵 唯一鍵 外來鍵 check約束 欄位名稱 字段型別 字段特徵 是否為null,預設值 標識列 主鍵 唯一鍵 外來鍵 check約束 建立老師表teacher id name gender age...