2、安装mysql

3、创建数据库

创建users表

CREATE TABLE `users` (
`user_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`create_time` datetime NOT NULL,
`nickname` varchar(32) NOT NULL,
`password` varchar(100) NOT NULL,
`email` varchar(100) NOT NULL,
`avatar` varchar(100) DEFAULT NULL,
`verify` varchar(10) NOT NULL,
`fans_count` int(10) unsigned NOT NULL,
`follow_count` int(10) unsigned NOT NULL,
`note_count` int(10) unsigned NOT NULL,
`description` varchar(1000) DEFAULT NULL,
PRIMARY KEY (`user_id`)
)

修改字段名

mysql> alter table users change id user_id INT UNSIGNED  AUTO_INCREMENT;
alter table users add expires datetime null;
ALTER TABLE users ADD sns VARCHAR(20) NULL;
ALTER TABLE users ADD sns_uid VARCHAR(50) NULL;
 
ALTER TABLE users ADD sns_access_token VARCHAR(100) NULL;
ALTER TABLE users ADD sns_expires datetime NULL;

创建follow表

CREATE TABLE `follow` (
`create_time` datetime NOT NULL,
`follower_id` int(10) unsigned NOT NULL,
`feeder_id` int(10) unsigned NOT NULL,
PRIMARY KEY (`follower_id`,`feeder_id`),
KEY `feeder_id` (`feeder_id`),
CONSTRAINT `follow_ibfk_1` FOREIGN KEY (`follower_id`) REFERENCES `users` (`user_id`),
CONSTRAINT `follow_ibfk_2` FOREIGN KEY (`feeder_id`) REFERENCES `users` (`user_id`)
)

创建filter表

CREATE TABLE filter
(
filter_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY(filter_id),
name VARCHAR(40) NOT NULL,
tag_count INT UNSIGNED NOT NULL,
user_id INT UNSIGNED NOT NULL,FOREIGN KEY (user_id) REFERENCES users (user_id)
);

创建tag表

CREATE TABLE tag
(
tag_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY(tag_id),
name VARCHAR(40) NOT NULL,
link VARCHAR(100) NULL,
picture VARCHAR(100) NULL,
description VARCHAR(200) NULL,
privacy VARCHAR(10) NOT NULL,
note_count INT UNSIGNED NOT NULL,
create_time DATE NOT NULL,user_id INT UNSIGNED NOT NULL,
filter_id INT UNSIGNED NULL,FOREIGN KEY (user_id) REFERENCES users (user_id),
FOREIGN KEY (filter_id) REFERENCES filter (filter_id)
);

修改

ALTER TABLE tag ADD width int(5) NULL;
ALTER TABLE tag ADD height int(5) NULL;
alter table tag change filter_id filter_id INT UNSIGNED NULL;

创建note表

CREATE TABLE note
(
note_id INT UNSIGNED NOT NULL AUTO_INCREMENT,
PRIMARY KEY(note_id),
type VARCHAR(20) NOT NULL,
create_time DATE NOT NULL,
privacy VARCHAR(10) NOT NULL,
user_id INT UNSIGNED NOT NULL,
tag_id INT UNSIGNED NULL,
FOREIGN KEY (user_id) REFERENCES users (user_id),
FOREIGN KEY (tag_id) REFERENCES tag (tag_id)
);

ALTER TABLE note ADD is_feed VARCHAR(10) NOT NULL;

创建markdown

CREATE TABLE markdown
(
note_id INT UNSIGNED NOT NULL,
PRIMARY KEY(note_id),
title VARCHAR(100) NOT NULL,
content VARCHAR(10000) NOT NULL,
FOREIGN KEY (note_id) REFERENCES note (note_id)
);

创建word表

CREATE TABLE word
(
note_id INT UNSIGNED NOT NULL,
PRIMARY KEY(note_id),
word VARCHAR(10000) NOT NULL,
FOREIGN KEY (note_id) REFERENCES note (note_id)
);

alter table word change word_content word VARCHAR(10000) NOT NULL;

创建picture表

CREATE TABLE picture
(
note_id INT UNSIGNED NOT NULL,
PRIMARY KEY(note_id),
pictrue_content VARCHAR(100) NOT NULL,
pictrue_description VARCHAR(200) NULL,
FOREIGN KEY (note_id) REFERENCES note (note_id)
);

alter table picture change pictrue_content picture  VARCHAR(100) NOT NULL;
alter table picture change pictrue_description description VARCHAR(200) NULL;

创建拓扑图

CREATE TABLE `topologys` (
`name` varchar(100) NOT NULL,
`status` varchar(10) NOT NULL,
`type` varchar(10) NOT NULL,
`description` varchar(1000) NULL,
`note_id` int unsigned NOT NULL,
PRIMARY KEY (`note_id`),
FOREIGN KEY (`note_id`) REFERENCES `note` (`note_id`)
)
CREATE TABLE `topology` (
`topology_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`create_time` datetime NOT NULL,
`name` varchar(100) NOT NULL,
`status` varchar(10) NOT NULL,
`type` varchar(10) NOT NULL,
`link` varchar(100) NULL,
`description` varchar(1000) NULL,
`parent_id` int unsigned NULL,
`note_id` int unsigned NOT NULL,
PRIMARY KEY (`topology_id`),
FOREIGN KEY (`parent_id`) REFERENCES `topology` (`topology_id`),
FOREIGN KEY (`note_id`) REFERENCES `note` (`note_id`)
)

查询note

SELECT note.note_id, note.type, note.create_time, note.privacy, note.user_id, note.tag_id,
word.word as word_content,
picture.picture as picture_content, picture.description as picture_description,
users.nickname, users.avatar
FROM note LEFT JOIN word ON note.note_id = word.note_id
LEFT JOIN picture ON note.note_id = picture.note_id
LEFT JOIN users ON note.user_id = users.user_id;

创建video表

CREATE TABLE video
(
note_id INT UNSIGNED NOT NULL,
PRIMARY KEY(note_id),
pageurl VARCHAR(100) NOT NULL,
swfurl VARCHAR(100) NOT NULL,
preview VARCHAR(100) NOT NULL,
description VARCHAR(200) NULL,
FOREIGN KEY (note_id) REFERENCES note (note_id)
);

创建link表

CREATE TABLE link
(
note_id INT UNSIGNED NOT NULL,
PRIMARY KEY(note_id),
link VARCHAR(100) NOT NULL,
description VARCHAR(200) NULL,
FOREIGN KEY (note_id) REFERENCES note (note_id)
);

创建card表

CREATE TABLE card
(
note_id INT UNSIGNED NOT NULL,
PRIMARY KEY(note_id),
name VARCHAR(32) NOT NULL,
picture VARCHAR(100) NOT NULL,
location VARCHAR(100) NULL,
weibo VARCHAR(100) NULL,
blog VARCHAR(100) NULL,
taobao VARCHAR(100) NULL,
facebook VARCHAR(100) NULL,
twitter VARCHAR(100) NULL,
instagram VARCHAR(100) NULL,
tumblr VARCHAR(100) NULL,
github VARCHAR(100) NULL,
link VARCHAR(100) NULL,
description VARCHAR(200) NULL,
FOREIGN KEY (note_id) REFERENCES note (note_id)
);

alter table follow change create_time create_time DATETIME NOT NULL;
alter table note change create_time create_time DATETIME NOT NULL;
alter table tag change create_time create_time DATETIME NOT NULL;
alter table users change create_time create_time DATETIME NOT NULL;

收藏

CREATE TABLE `tagfav` (
`tag_id` INT UNSIGNED NOT NULL,
`user_id` INT UNSIGNED NOT NULL,
`create_time` datetime NOT NULL,
PRIMARY KEY (`tag_id`, `user_id`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`tag_id`) REFERENCES `tag` (`tag_id`),
FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`)
); CREATE TABLE `notefav` (
`note_id` INT UNSIGNED NOT NULL,
`user_id` INT UNSIGNED NOT NULL,
`create_time` datetime NOT NULL,
PRIMARY KEY (`note_id`, `user_id`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`note_id`) REFERENCES `note` (`note_id`),
FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`)
);

点赞

CREATE TABLE `taglike` (
`tag_id` INT UNSIGNED NOT NULL,
`user_id` INT UNSIGNED NOT NULL,
`create_time` datetime NOT NULL,
PRIMARY KEY (`tag_id`, `user_id`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`tag_id`) REFERENCES `tag` (`tag_id`),
FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`)
); CREATE TABLE `notelike` (
`note_id` INT UNSIGNED NOT NULL,
`user_id` INT UNSIGNED NOT NULL,
`create_time` datetime NOT NULL,
PRIMARY KEY (`note_id`, `user_id`),
KEY `user_id` (`user_id`),
FOREIGN KEY (`note_id`) REFERENCES `note` (`note_id`),
FOREIGN KEY (`user_id`) REFERENCES `users` (`user_id`)
);
alter table tag drop FOREIGN KEY `tag_ibfk_1`;
alter table `tag` add CONSTRAINT `tag_ibfk_1` FOREIGN KEY (`category_id`) REFERENCES `user_category` (`category_id`) ;

nanakon的更多相关文章

  1. git全局忽略文件

    mac系统如何显示和隐藏文件 创建 ~/.gitignore_global .DS_Store __pycache__/ 配置选项 git config --global core.excludesf ...

随机推荐

  1. JDK中常见的package

    SUN公司在JDK中为程序开发者提供了各种实用类,这些类按功能不同分别被放入了不同的包中,供开发者使用,下面简要介绍其中最常用的几个包:1. java.lang — 包含一些Java语言的核心类,如S ...

  2. Raphaël 是一个小型的 JavaScript 库,用来简化在页面上显示向量图的工作。你可以用它在页面上绘制各种图表、并进行图片的剪切、旋转等操作。

    点这里 在线效果演示:http://raphaeljs.com/pie.html http://raphaeljs.com github: https://github.com/DmitryBaran ...

  3. asp.net网站中添加百度地图功能

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...

  4. Eclipse里面开发ExtJS程序

    首先在http://extjs.org.cn/download下载ext ,我下载的版本是ext-3.4.1.1-gpl,下载好以后解压. 然后在eclipse里面先建立一个web项目,建立好后再we ...

  5. C#调用脚本语言(三)-- IronJS 与 IronLua 简单方法性能比较

    1.   测试环境 1.1. 硬件环境 CPU:intel Core i7-740QM 内存:8GDDR3 Memory 1.2. 系统 系统:Windows 8 Enterprise 开发工具:Vs ...

  6. DOS永久设置系统环境变量-WMIC

    wmic Windows Management Instrumentation Command-line(Windows管理规范命令行) WMIC扩展WMI(Windows Management In ...

  7. 传说中的WCF(2):服务协定的那些事儿

    上一篇文章中,我们抛出了N个问题:WCF到底难不难学?复杂吗?如果复杂,可以化繁为简吗? 其实,这些问题的答案全取决于你的心态,都说“态度决定一切”,这句话,不知道各位信不信,反正我是信了.首先,敢于 ...

  8. 基于ant的jmeter自动化性能测试

    准备工作: 1.java的运行环境正常,及运行java -version.javac -version能正常输出java版本: 2.ant的运行环境正常,使用ant需要配置环境变量,编辑/etc/pr ...

  9. oci.dll文件是用来干嘛的? 如果没有安装ORACLE客户端提示oci.dll未加载

    oracle数据库开发编程中,没有找到oci.dll,一般是系统的 path 设置有问题, 查找oci.dll, 然后加入到系统路径.oci.dll 可下载解压到系统盘的system32目录下.然后打 ...

  10. 545E. Paths and Trees

    题目链接 题意:给定一个无向图和一个点u,找出若干条边组成一个子图,要求这个子图中u到其他个点的最短距离与在原图中的相等,并且要求子图所有边的权重之和最小,求出最小值并输出子图的边号. 思路:先求一遍 ...