主鍵約束的建立有兩種情況:有名型和無名型,
1 有名型:
create table students (
studentid int ,
studentname varchar(8),
age int,
constraint yy primary key(studentid)
);或者
create table nbia_risk_info(
id number(10) not null,
riskcode varchar2(10) not null,
riskcname varchar2(20) not null,
riskename varchar2(20) ,
classcode varchar2(10) not null,
newriskcode varchar2(10) not null,
riskflag varchar2(10) ,
flag varchar2(10),
vaildstatus varchar2(1) not null
);alter table nbia_risk_info add constraint pk_nbia_risk_info primary key (id);
這樣建立的主鍵都是有名字的,yy 和 pk_nbia_risk_info
2 無名型
create table nbia_timetasklog(
id number(10) primary key,
tasktype varchar2(20) not null,
taskname varchar2(100) not null,
channeltype varchar2(2) not null,
bankcode varchar2(2) ,
banksite varchar2(20) ,
excutetime date not null,
sucflag varchar2(1) not null,
failreason varchar2(1000)
);這樣的主鍵建立的時候沒有命名。
刪除約束:(1 )有名型 alter table table_name drop constraint pk_name
eg:alter table nbia_risk_info drop constraint pk_nbia_risk_info;
(2 )無名型
兩步操作 :
i 查詢預設主鍵名稱 select constraint _name from user_constraints where table_name='';
ii 刪除主鍵 (1)
另:是約束失效的sql:alter table tbl_employee disable constraint constraint_name;
Oralce資料庫表資料還原
在執行插入 更新 刪除等操作時,容易產生誤操作,導致資料庫中的內容被修改,通過普通的sql操作無法還原,則可採用oralce資料庫表的閃回機制,將表資料還原到某個時間點,具體如下 先查詢某個時間點的資料是否為要還原的資料 select from tablename as of timestamp t...
mysql刪除表主鍵約束 MySQL新增約束
mysql新增約束 刪除約束及修改約束 mysql刪除約束 將t student 刪除外來鍵約束 alter table 表名 drop foreign key 外來鍵 區分大小寫 alter table t student drop foreign key fk classes id 刪除主鍵約束...
資料庫 MySQL中刪除主鍵
在mysql中刪除主鍵需要兩步.1 如果有auto increment,先刪除之 2 刪除主鍵約束 primary key.例如 1 假設我們有個表products.裡面的pid為主鍵,並且是自增長,我們需要刪除其主鍵以及自增長。結構如下 2 我們刪除pid的auto increment約束。命令為...