create table product(
Product_id varchar2(10) not null,
Product_name varchar2(20),
ProductPrice number(8,2),
Quantity number(10),
Category varchar2(10),
Desperation varchar2(1000),
Origin varchar2(10)
);
drop table product;
alter table product
add remark varchar2(200);--增加列remark
alter table product
modify remark number(10,2);--修改列remark datatype
select *from product
alter table product drop column remark;--删除列remark
alter table product add constraints pk_product primary key(Product_id);--主键是由一个列组成
alter table product add constraints pk_product primary key(Product_id,product_name);--主键是由两个列组成
create table categoryinfo(
CategoryId varchar2(10),
CategoryName varchar2(30),
primary key(CategoryId)
);
drop table categoryinfo
alter table product
Drop constraint pk_product
create table productinfo1(
Product_id varchar2(10) not null,
Product_name varchar2(20),
ProductPrice number(8,2),
Quantity number(10),
Category varchar2(10),
Desperation varchar2(1000),
Origin varchar2(10),
primary key(Category),
constraint fk_pro foreign key(category)
references categoryinfo(CategoryId)
);
alter table productinfo1
add Constraint fk_pro foreign key(category)
References categoryinfo(CategoryId);
本文详细介绍了如何创建和管理数据库表,包括定义字段类型、添加和删除字段、设置主键约束以及创建外键关联等关键步骤。通过具体示例展示了表结构的设计过程及其调整方法。
586

被折叠的 条评论
为什么被折叠?



