create table net_top(switch_pos int, floor int);
create table net_port(room int primary key, port1 int default 0, port2 int default 0);
create table net_mac_addr(room int references net_port(room),
mac_addr varchar(30) unique check (mac_addr ~ '^(00)[0-9A-F]{10}$'),
ip_addr varchar(30) check (ip_addr ~ '[0-9]{3}(\.[0-9]{1,3}){3}$'),
owner varchar(20)
);
create view net_room_view as
select * from net_top t left outer join net_port p
on (p.room/100=t.floor or p.room=t.floor);
create view net_owner_view as
select n.room, n.mac_addr, n.ip_addr, n.owner, p.port1, p.port2
from net_mac_addr n left outer join net_port p
on (n.room=p.room);
存在'E:\dbase_related\net_mgr.sql'中,然后在命令行中执行
psql -U postgres -f e:\dbase_related\net_mgr.sql
就行了。