表的建立和維護

2021-06-18 19:15:54 字數 849 閱讀 3471

表的建立和維護

修改表的約束條件:

1.增加商品名稱不能為空 alter table goods modify  goodsname not null;

2.增加身份證不能重複 alter table customer add constraint card_unique(cardid);

3.增加客戶的住址只能是「北京」「上海」alter table customer add constraint address_check check (address in ('北京','上海'));

刪除約束

當不再需要某個約束時,可以刪除。

alter table 表名 drop constraint 約束名稱;

當刪除主鍵約束時,可能有錯誤,例如:

alter table 表名 drop  primary key;

因為兩張表之間可能存在主從關係,可以用

alter table 表名 drop primary key  cascade;

現實約束資訊:

1.顯示約束資訊

通過查詢資料字典檢視user_constraints,可以顯示當前使用者所有的約束資訊。

select constraint_name,constraint_type,status,validated from user_constraints  where table_name='表名';

2.顯示約束列

通過查詢資料字典檢視user_cons_columns,可以顯示約束所對應的表列資訊。

select column_name,position from user_cons_columns where constraint_name='約束名';

oracle建立和維護表

1 oracle中資料庫物件命名原則 必須由字母開始,長度在1 30個字元之間 名字中只能包含a z,a z,0 0,和 同乙個oracle伺服器使用者所擁有的物件名字不能重複。名字不能為oracle的保留字 名字是大小寫不敏感的 2 建立表的語法 create table schema.table...

sql建立和維護表

建立和維護表 這一章的操作是對 本身的操作,這些操作都是立即生效的,同時會將所有沒有提交的修改一次性提次 建立 sql語句 語法 create table 表名 列名1 資料型別 default 值,列名2 資料型別 default 值,說明 資料型別是指該列能夠儲存的資料型別 default指出如...

表的建立和使用

本次程式設計任務是 在右側編輯區 create table 下的 begin end 區域補全 建立 student course 和 score 三個表 在右側編輯區 insert 下的 begin end 區域補全 向 score 表中插入下面給出的資料 在右側編輯區 alt student t...