数据库表中的键

2023年 9月 12日 37.0k 0

CREATE table student(
s_id integer,
s_name varchar(100),
gender char(2),
PIN CHAR(18),
UNIQUE (PIN)
);#’指定一个候选键’

CREATE table student_BAK20230910(
s_id integer,
s_name varchar(100),
gender char(2),
PIN CHAR(18),
UNIQUE (PIN,S_ID)
);#’指定多个组合候选键’

CREATE table student_score(
s_id int,
c_id int,
score int,
primary key(c_id)
);#指定主键

CREATE table student_score( s_id int , primary key, c_id int, score int);#指定主键

CREATE table student_score_bak20230910(
s_id int,
c_id int,
score int,
primary key(c_id,s_id)
);#指定组合主键

CREATE table student_score2(
s_id int ,
c_id int,
score int,
primary key(c_id),
foreign key(s_id) references student(s_id)
);#指定外键主键 #被关联表的字段必须是主键才行

alter table student add constraint primary key(s_id); #增加主键

alter table student drop constraint primary key(s_id); #删除主键

相关文章

pt-kill工具的使用
pt-ioprofile工具包的使用
数据库管理-第216期 Oracle的高可用-01(20240703)
DBMS_REPAIR EXAMPLE SCRIPT WITH PARTITION
数据库事务的四大特性: ACID 
使用BBED修复损坏的SYSTEM文件头

发布评论