Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/mercurial/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Mysql 写表的SQL语句?_Mysql_Sql - Fatal编程技术网

Mysql 写表的SQL语句?

Mysql 写表的SQL语句?,mysql,sql,Mysql,Sql,从事社交网络项目。只需将sql语句放在一起创建表,就需要一些帮助来了解如何实现这一点,以及表之间的关系如何工作 drop table users; drop table intrest; drop table friendships; create table users( id INT, Fname char(15), Lname char(15), email char(20), street char(15), state char(2), zip INT, age INT, gende

从事社交网络项目。只需将sql语句放在一起创建表,就需要一些帮助来了解如何实现这一点,以及表之间的关系如何工作

drop table users;
drop table intrest;
drop table friendships;

create table users(
id INT,
Fname char(15),
Lname char(15),
email char(20),
street char(15),
state char(2),
zip INT,
age INT,
gender char (2),
phone INT,
Password char(15),
primary key (id);

create table Instrests(
id INT,

create table friendships(
这只需要三张桌子就可以完成

到目前为止,我已经做到了

drop table users;
drop table intrest;
drop table friendships;

create table users(
id INT,
Fname char(15),
Lname char(15),
email char(20),
street char(15),
state char(2),
zip INT,
age INT,
gender char (2),
phone INT,
User_password char(15),
primary key (id)
foriegn key (intrest_id) references intrest(id)
);

create table Intrests(
id INT,
description char(30),
Primary key (id),
foreign key (users_id) references users(id)
);

create table User_intrest(
foreign key (user_id) references user(id),
foreign key (intrest_id) references intrest(id)
);


create friendships(
User_1_id INT,
User_2_id INT,
status Char(20),
foreign key (user_id) references user(id)
);

看起来你在问如何创建兴趣和友谊表?它们是如何联系在一起的

首先,您需要在drop和create语句中拼写相同的兴趣。您是对的,兴趣将通过ID链接回用户。您可能需要一个带有InterestID和description的兴趣表,以及一个带有UserID和InterestID的链接表。否则,您将列出许多重复的兴趣,每个用户一个

友谊表可能只是一个链接表,将两个用户标识链接在一起

试着想象一下您需要的数据,并根据这些数据创建表:

User - 1, name - Joe, other info... 
User - 2, name - Kris, other info..
User - 3, name - Lee, other info...
Interest - 1, name - reading
Interest - 2, name - parasailing
Interest - 3, name - skimboarding
UserInterest - User 1, Interest 2
UserInterest - User 1, Interest 3
UserInterest - User 2, Interest 2
Friendship - User 1, User 2
这说明乔和克里斯是朋友,他们都喜欢乘伞,尽管乔也喜欢冲浪


这并没有告诉您如何创建表,但它可能会为您指明正确的方向。如果这是一个家庭作业,而且看起来是这样,那么您仍然希望自己完成这项工作。

如果您计划在两个表之间建立多对多关系,则需要在用户和兴趣之间建立一个中间表

同样对于友谊,我建议在友谊和用户之间建立一个中间表,该表有一个指向“友谊类型”表的链接,以标识友谊/关系

如果周四周是正确的,这是一个家庭作业,那么我将在这里停止我的建议,因为中间表还有更多的内容需要在实施之前了解

drop table users;
drop table intrest;
drop table friendships;

create table users(
id INT,
Fname char(15),
Lname char(15),
email char(20),
street char(15),
state char(2),
zip INT,
age INT,
gender char (2),
phone INT,
User_password char(15),
primary key (id)
foriegn key (intrest_id) references intrest(id)
);

create table Intrests(
id INT,
description char(30),
Primary key (id),
foreign key (users_id) references users(id)
);
create table User_intrest(
foreign key (user_id) references user(id),
foreign key (intrest_id) references intrest(id)
);


create friendships(
User_1_id INT,
User_2_id INT,
status Char(20),
foreign key (user_id) references user(id)
);

很抱歉,我不太擅长这一点,无论如何,这是我迄今为止为sql语句所做的。

这看起来不是一个完整的问题。。。请阅读并添加您的全部代码!