DROP DATABASE IF EXISTS microblog;
CREATE DATABASE microblog;
USE microblog;

CREATE TABLE tright (
  tr_id bigint(11) NOT NULL auto_increment,
  right_name varchar(50) NOT NULL,
  right_url varchar(100) default NULL,
  description varchar(255) default NULL,
  PRIMARY KEY  (tr_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE trole (
  tr_id bigint(11) NOT NULL auto_increment,
  role_name varchar(50) NOT NULL,
  description varchar(255) default NULL,
  create_time datetime NOT NULL,
  PRIMARY KEY  (tr_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE tuser (
  login_name varchar(50) NOT NULL,
  user_passwd varchar(50) NOT NULL,
  real_name varchar(50) default NULL,
  tel varchar(20) default NULL,
  email varchar(100) default NULL,
  create_time datetime NOT NULL,
  login_time datetime default NULL,
  last_login_time datetime default NULL,
  login_times int(11) default '0',
  PRIMARY KEY  (login_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE trolerightrelation (
  trr_id bigint(11) NOT NULL auto_increment,
  role_id bigint(11) NOT NULL default '0',
  right_id bigint(11) NOT NULL default '0',
  PRIMARY KEY  (trr_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE tuserrolerelation (
  tur_id bigint(11) NOT NULL auto_increment,
  login_name varchar(50) NOT NULL,
  role_id bigint(11) default NULL,
  PRIMARY KEY  (tur_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE tusermicroblog (
  login_name varchar(50) NOT NULL,
  birth_date varchar(8) NOT NULL,
  sex int(4) NOT NULL default '0',
  province varchar(10) default NULL,
  city varchar(10) default NULL,
  description varchar(255) default NULL,
  img_url varchar(255) NOT NULL,
  PRIMARY KEY  (login_name)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE tbroadcast (
  broadcast_id bigint(11) NOT NULL auto_increment,
  login_name varchar(50) NOT NULL,
  content varchar(255) NOT NULL,
  create_time datetime NOT NULL,
  PRIMARY KEY  (broadcast_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE tlistenuser (
  id bigint(11) NOT NULL auto_increment,
  login_name varchar(50) NOT NULL,
  listened_user varchar(50) NOT NULL,
  create_tim datetime NOT NULL,
  PRIMARY KEY  (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


CREATE TABLE trebroadcast (
  id bigint(11) NOT NULL auto_increment,
  rebroadcast_user varchar(50) NOT NULL,
  login_name varchar(50) NOT NULL,
  rebroadcast_time datetime NOT NULL,
  PRIMARY KEY  (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
