类别编号 | 类别名称 | 父类别编号 |
---|---|---|
1 | 计算机类 | 0 |
2 | 英语类 | 0 |
图书信息表:
图书编号 | 图书名称 | 出版社 |
---|---|---|
101 | linux编程艺术 | 人民出版社 |
102 | android开发艺术探索 | 机械工业出版社 |
create table book_info(
book_id int,
book_name varchar(20) not null
);
alter table book_info modify book_name varchar(20) not nul;
alter table book_info modify book_name varchar(20);
create table book_info(
book_id int,
book_name varchar(20) unique
);
create table book_info(
book_id int,
book_name varchar(20),
constraint unique_name unique(book_name)
);
alter table book_info modify book_name varchar(20) unique;
alter table book_info add constraint unique_name unique(book_name);
alter table book_info drop index unique_name;
alter table book_info drop key book_name;
create table book_info(
book_id int,
press varchar(20) default’人民出版社’
);
alter table book_info modify press varchar(20) default’人民出版社’;
alter table book_info alter column press set default ‘人民出版社’;
alter table book_info modify press varchar(20);
alter table book_info alter column press drop default;
主键:(not null,unique,唯一标识一条记录)
create table book_info(
book_id int primary key,
book_name varchar(20)
);
create table book_info(
book_id int,
book_name varchar(20),
constraint pk_id primary key(book_id)
);
create table book_info(
book_id int,
book_name varchar(20),
constraint pk_id_name primary key(book_id,book_name)
);
alter table book_info modify book_id int primary key;
alter table book_info add constraint pk_id primary key(book_id);
alter table book_info drop primary key;
create table book_category(
category_id int primary key,
category_name varchar(20),
parent_id int
);
create table book_info(
book_id int primary key,
book_name varchar(20),
category_id int,
constraint fk_category foreign key(category_id)
references book_category(category_id)
);
alter table book_info
add constraint fk_category foreign key(category_id)
references book_category(category_id);
alter table book_info drop foreign key fk_category;
create table book_category(
category_id int primary key,
category_name varchar(20),
parent_id int
);
create table book_info(
book_id int primary key,
book_name varchar(20),
category_id int,
constraint fk_category foreign key(category_id)
references book_category(category_id) on delete cascade
);