学习时的一些脚本,记录下来:
drop table user_orders;
create table user_orders (
user_id int8 references userinfos(user_id),
order_id int8 references orders(order_id)
);
drop table user_orders;
create table user_orders (
user_id int8,
order_id int8,
foreign key (user_id) references userinfos(user_id),
foreign key (order_id) references orders(order_id)
);
drop table partners;
create table partners
(
partner_id int8 primary key,
partner_name varchar(80)
);
drop table partner_tables;
create table partner_orders
(
partner_id int8 references partners(partner_id),
order_id int8 references orders(order_id),
primary key (partner_id,order_id)
);
drop table prepaid_cards;
create table prepaid_cards
(
prepaid_card_id int8 primary key,
price float
)
drop table packages;
create table packages
(
package_id int8 primary key,
package_name varchar(80)
);
drop table package_cards;
create table package_cards
(
package_id int8 references packages(package_id),
prepaid_card_id int8 references prepaid_cards(prepaid_card_id),
primary key (package_id,prepaid_card_id)
);
drop table prepaid_cards;
create table prepaid_cards
(
prepaid_card_id int8 primary key,
prepaid_card_no varchar(30)
)
drop table order_detials;
create table order_detials
(
order_id int8 references orders(order_id),
package_id int8 references packages(package_id),
count int4 ,
primary key (order_id,package_id)
)
drop table aa;
create table aa
(
user_id int8 default nextval('seq_user_id') primary key ,
user_name varchar(40)
);
drop table category;
create table category
(
category_id int8 primary key,
parent_id int8 references category(category_id),
category_name varchar(80)
);
drop sequence seq_category_id ;
create sequence seq_category_id increment 1 start 300000;
alter table category alter column category_id set default nextval('seq_category_id');