日期:2014-05-16 浏览次数:20447 次
create table company( id int primary key unique not null, name varchar(80) default '' ); create table person( id int primary key unique not null, code varchar(32) not null unique, name varchar(32) default '', company_id int references company(id) );
ALTER TABLE public.person DROP CONSTRAINT person_company_id_fkey ; DROP TABLE public.person ; DROP TABLE public.company ; CREATE TABLE public.person( id INTEGER NOT NULL, code VARCHAR(32) NOT NULL, name VARCHAR(32) DEFAULT '::character varying', company_id INTEGER, PRIMARY KEY (id) ) ; CREATE TABLE public.company( id INTEGER NOT NULL, name VARCHAR(80) DEFAULT '::character varying', PRIMARY KEY (id) ) ; ALTER TABLE public.person ADD CONSTRAINT person_company_id_fkey FOREIGN KEY (company_id) REFERENCES public.company (id) ;