数据库实现的留言板
来源:互联网 发布:go高效实践编程 编辑:程序博客网 时间:2024/05/19 18:15
mysql> create database qq
-> character set gb2312
-> collate gb2312_chinese_ci;
Query OK, 1 row affected (0.02 sec)
mysql> use qq
Database changed
mysql> create table user
-> (uid varchar(20) not null,u_password varchar(20) not null,u_birthday date,u_address varchar(200),
telephone varchar(15),e_mail varchar(30) not null,
-> primary key(uid));
Query OK, 0 rows affected (0.08 sec)
mysql> desc user;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| uid | varchar(20) | NO | PRI | | |
| u_password | varchar(20) | NO | | | |
| u_birthday | date | YES | | NULL | |
| u_address | varchar(200) | YES | | NULL | |
| telephone | varchar(15) | YES | | NULL | |
| e_mail | varchar(30) | NO | | | |
+------------+--------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
mysql> create table com
-> (id bigint not null auto_increment,title varchar(100) not null,
-> uid varchar(20) not null,uid2 varchar(20) not null,content varchar(2000),
-> primary key(id));
Query OK, 0 rows affected (0.05 sec)
mysql> desc com;
+---------+---------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| title | varchar(100) | NO | | | |
| uid | varchar(20) | NO | | | |
| uid2 | varchar(20) | NO | | | |
| content | varchar(2000) | YES | | NULL | |
+---------+---------------+------+-----+---------+----------------+
5 rows in set (0.00 sec)
mysql> alter table com
-> add constraint fk_uid1 foreign key (uid) references user(uid);
Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table com
-> add constraint fk_uid2 foreign key (uid2) references user(uid);
Query OK, 0 rows affected (0.11 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> show indexes from com;
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
| com | 0 | PRIMARY | 1 | id | A | 0 | NULL | NULL | | BTREE | |
| com | 1 | fk_uid1 | 1 | uid | A | 0 | NULL | NULL | | BTREE | |
| com | 1 | fk_uid2 | 1 | uid2 | A | 0 | NULL | NULL | | BTREE | |
+-------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+
3 rows in set (0.00 sec)
mysql> create table friend
-> (uid varchar(20),uid2 varchar(20),primary key (uid,uid2));
Query OK, 0 rows affected (0.05 sec)
mysql> alter table friend
-> add constraint fk_uf1 foreign key (uid) references user(uid);
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> alter table friend\
-> c
-> \c
mysql> alter table friend
-> add constraint fk_uf2 foreign key (uid2) references user(uid);
Query OK, 0 rows affected (0.09 sec)
Records: 0 Duplicates: 0 Warnings: 0
mysql> desc user
-> ;
+------------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+--------------+------+-----+---------+-------+
| uid | varchar(20) | NO | PRI | | |
| u_password | varchar(20) | NO | | | |
| u_birthday | date | YES | | NULL | |
| u_address | varchar(200) | YES | | NULL | |
| telephone | varchar(15) | YES | | NULL | |
| e_mail | varchar(30) | NO | | | |
+------------+--------------+------+-----+---------+-------+
6 rows in set (0.00 sec)
mysql> insert into user
-> values('hello','123456','1999-2-5',null,'12356486541','aa@sina.com');
Query OK, 1 row affected (0.03 sec)
mysql> insert into user
-> values('nihao','123456','1999-2-5',null,'12356486541','aaa@sina.com');
Query OK, 1 row affected (0.01 sec)
mysql> insert into user
-> values('july','123456','1999-2-5',null,'12356486541','aaaaa@sina.com');
Query OK, 1 row affected (0.02 sec)
mysql> insert into user
-> values('marry','123456','1999-2-5',null,'12356486541','aaaaa@sina.com');
Query OK, 1 row affected (0.01 sec)
mysql> insert into user
-> values('wangwu','123456','1999-2-5',null,'12356486541','aaaaa@sina.com');
Query OK, 1 row affected (0.02 sec)
mysql> insert into friend
-> values('july','wangwu');
Query OK, 1 row affected (0.01 sec)
mysql> insert into friend
-> values('july','hello');
Query OK, 1 row affected (0.01 sec)
mysql> insert into friend
-> values('july','nihao');
Query OK, 1 row affected (0.02 sec)
mysql> insert into friend
-> values('hello','nihao');
Query OK, 1 row affected (0.03 sec)
mysql> insert into friend
-> values('marry','nihao');
Query OK, 1 row affected (0.02 sec)
mysql> insert into friend
-> values('hello','july');
Query OK, 1 row affected (0.03 sec)
mysql> select * from user;
+--------+------------+------------+-----------+-------------+----------------+
| uid | u_password | u_birthday | u_address | telephone | e_mail |
+--------+------------+------------+-----------+-------------+----------------+
| hello | 123456 | 1999-02-05 | NULL | 12356486541 | aa@sina.com |
| july | 123456 | 1999-02-05 | NULL | 12356486541 | aaaaa@sina.com |
| marry | 123456 | 1999-02-05 | NULL | 12356486541 | aaaaa@sina.com |
| nihao | 123456 | 1999-02-05 | NULL | 12356486541 | aaa@sina.com |
| wangwu | 123456 | 1999-02-05 | NULL | 12356486541 | aaaaa@sina.com |
+--------+------------+------------+-----------+-------------+----------------+
5 rows in set (0.01 sec)
mysql> select * from friend;
+-------+--------+
| uid | uid2 |
+-------+--------+
| july | hello |
| hello | july |
| hello | nihao |
| july | nihao |
| marry | nihao |
| july | wangwu |
+-------+--------+
6 rows in set (0.00 sec)
mysql> select uid2 from friend
-> where uid='july';
+--------+
| uid2 |
+--------+
| hello |
| nihao |
| wangwu |
+--------+
3 rows in set (0.01 se
mysql> set names gbk;
Query OK, 0 rows affected (0.01 sec)
mysql> insert into com
-> values(1,'welcome','july','hello','欢迎您!');
Query OK, 1 row affected (0.03 sec)
mysql> insert into com(title,uid,uid2,content)
-> values('你好','july','hello','你好啊');
Query OK, 1 row affected (0.01 sec)
mysql> select * from com;
+----+---------+------+-------+----------+
| id | title | uid | uid2 | content |
+----+---------+------+-------+----------+
| 1 | welcome | july | hello | 欢迎您! |
| 2 | 你好 | july | hello | 你好啊 |
+----+---------+------+-------+----------+
2 rows in set (0.00 sec)
mysql> insert into com(title,uid,uid2,content)
-> values('你好','july','wangwu','你好啊');
Query OK, 1 row affected (0.03 sec)
mysql> select com.uid,uid2,u_address,telephone,u_birthday,content from
-> com join user on com.uid2=user.uid;
+------+--------+-----------+-------------+------------+----------+
| uid | uid2 | u_address | telephone | u_birthday | content |
+------+--------+-----------+-------------+------------+----------+
| july | hello | NULL | 12356486541 | 1999-02-05 | 欢迎您! |
| july | hello | NULL | 12356486541 | 1999-02-05 | 你好啊 |
| july | wangwu | NULL | 12356486541 | 1999-02-05 | 你好啊 |
+------+--------+-----------+-------------+------------+----------+
3 rows in set (0.00 sec)
mysql> select com.uid,uid2,u_address,telephone,u_birthday,content from
-> com join user on com.uid2=user.uid
-> where uid2='hello';
+------+-------+-----------+-------------+------------+----------+
| uid | uid2 | u_address | telephone | u_birthday | content |
+------+-------+-----------+-------------+------------+----------+
| july | hello | NULL | 12356486541 | 1999-02-05 | 欢迎您! |
| july | hello | NULL | 12356486541 | 1999-02-05 | 你好啊 |
+------+-------+-----------+-------------+------------+----------+
2 rows in set (0.00 sec)
mysql> notee
- 数据库实现的留言板
- 简单留言板的实现
- php结合mysql数据库实现简单留言板的功能
- php实现简单的留言板
- 网上商城留言板的实现——留言展示到留言板
- 一个简单的留言板的实现
- 用xml简单实现的留言板
- 一个留言板的三层结构实现方案
- 如何实现ajax+asp.net 的留言板
- 很简单的php留言板实现
- 实现有管理功能的ASP留言板
- yii2 实现简单的留言板组件
- PHP+MySql实现一个简单的留言板
- PHP+mysql实现简单的留言板
- vuejs+bootstrap实现简易的留言板功能
- Struts2实现的吊炸天留言板系统(包含完整源+mysql数据库+bootstraps3)源码以及课程报告下载地址!
- 留言板数据库设计
- 基于mysql数据库支持的留言板的实例
- (第Ⅲ部分 结构型模式篇) 第9章 装饰模式(Decorator Pattern)
- (第Ⅲ部分 结构型模式篇) 第10章 组合模式(Composite Pattern)
- Jasperreport连续打印多个报表模板
- as3常识,你不能不知道
- openwrt gpio开始 By 船长@发现——转载(终于找到)
- 数据库实现的留言板
- ThinkPHP
- OpenWrt与Arduino的USB直接通信 By 船长@第一次的硬软件结合
- iptables学习笔记--Netfilter的报文转发流程
- 今天学flash了,挺有意思的
- ubuntu右键添加打开终端的快捷菜单
- Django中的Q查询
- 由Lucene版本不同引起的一些问题
- hdu4296Buildings