mysql may to many
2015-08-13 18:01
555 查看
-- register three user
insert into user(username,password,address,register_time) values('james','123','shanghai',current_timestamp);
insert into user(username,password,address,register_time) values('dudu','123','beijing',current_timestamp);
insert into user(username,password,address,register_time) values('didi','123','shengzheng',current_timestamp);
-- user didi publish three project;
insert into project(project_name,price_estimation,techs_required,project_note,publish_time,publish_user,status)
values('didiproject1','5000-10000','java,spring','this is a balabala...',current_timestamp,'didi','p');
insert into project(project_name,price_estimation,techs_required,project_note,publish_time,publish_user,status)
values('didiproject2','3000-8000','Python','this is a balabala...',current_timestamp,'didi','p');
insert into project(project_name,price_estimation,techs_required,project_note,publish_time,publish_user,status)
values('didiproject3','10000-20000','PHP','this is a balabala...',current_timestamp,'didi','p');
-- user james request three project
insert into user_project(project_id,username,accepted) values(1,'james',false);
insert into user_project(project_id,username,accepted) values(2,'james',false);
insert into user_project(project_id,username,accepted) values(3,'james',false);
-- user dudu request three project
insert into user_project(project_id,username,accepted) values(1,'dudu',false);
insert into user_project(project_id,username,accepted) values(2,'dudu',false);
insert into user_project(project_id,username,accepted) values(3,'dudu',false);
-- user didi deal project
update user_project set accepted=true where project_id=1 and username='james';
update project set status='d' and deal_time=current_timestamp where project_id=1;
-- james get latest pulished project
select * from project where status='p' order by publish_time desc;
-- james get latest deal project
select * from project where status='d' order by deal_time desc;
-- didi get my published project
select * from project where publish_user='didi' order by publish_time;
-- james get my request project
select * from project p left join user_project up on p.project_id=up.project_id
where up.username='james';
drop table if exists user_project;
drop table if exists project;
drop table if exists user;
create table user(
username varchar(45) not null primary key,
password varchar(100) not null,
register_email varchar(30) ,
system_receive_email varchar(30) ,
nick_name varchar(30),
real_name varchar(30) ,
city varchar(20) ,
address varchar(50) not null,
area_code varchar(10) ,
mobile_phone varchar(20) ,
land_line varchar(20),
company_full_name varchar(50),
msn varchar(30),
qq varchar(30),
register_time timestamp not null
);
create table project(
project_id bigint not null primary key auto_increment,
project_name varchar(30) not null,
price_estimation varchar(20) not null,
competitor_count int,
techs_required varchar(100) not null,
project_note text not null,
project_show_days int,
publish_time timestamp not null,
deal_time timestamp,
publish_user varchar(45) not null,
status char(1) ,
constraint fk_publish_user_id_1 foreign key(publish_user) references user(username)
);
create table user_project(
project_id bigint not null ,
username varchar(45) not null,
accepted boolean not null default false,
primary key (project_id,username),
constraint fk_project_id_1 foreign key(project_id) references project(project_id),
constraint fk_user_id_1 foreign key(username) references user(username)
);
相关文章推荐
- Use mysql_num_rows() to find out how many rows were returned for a SELECT statement or mysql_affected_rows() to find out how man
- You have ettempted to queue to many files.You may select one files.
- Too Many Connections: How to Increase the MySQL Connection Count To Avoid This Problem
- You have ettempted to queue to many files.You may select one files.
- MySql Proccesslist filled with “Sleep” Entries leading to “Too many Connections”?
- mysql 找不到或无法加载已注册的 .Net Framework Data Provider和Unable to find the requested .Net Framework Data Provider. It may not be installed解决
- XAMPP启动apache,mysql报错:This may be due to a blocked port, missing dependencies...
- ReactNative警告:bind(): React component methods may only be bound to the component instance
- 使用Hibernate报错:MySQL server version for the right syntax to use near 'type=InnoDB' at line xxx
- 解决Navicat 报错:1130-host ... is not allowed to connect to this MySql server
- 安装mysql 出现错误Unable to update security settings. Access denied for user 'root'@'localhost' 的解决
- Parameter 2 to mysqli_stmt::bind_param() expected to be a reference
- 2013 Lost connection to MySQL server at 'handshake: reading initial communication packet'
- Mysql 错误too many connections解决方案
- Host 'admin-PC' is not allowed to connect to this MySQL server
- MySQL的连接参数---MySQL进不去error:'Too many connections'
- 使用 sqlyog 导入导出数据显示 lost connection to mysql server during query
- NoSQL to MySQL with Memcached
- 客户PW论坛访问出现:MYSQL:Too many connections ( 1040 )
- 一个完整的hibernate的one-to-many的例子