create table USERS(
ID int(8) not null primary key,
USERNAME varchar(40),
PASSWORD varchar(40)
);create table EMAIL(
USERID int(8),
EMAIL varchar(200),
foreign key (USERID) references USERS (ID)
);可以看得出来USERS跟EMAIL表有主外键关联的关系。平时我们在建表的同时总有个习惯就是drop table if exists 表名
于是我就有了定向思维,分别在两张表前加了一句。变成了这样:
drop table if exists USERS
create table USERS(
ID int(8) not null primary key,
USERNAME varchar(40),
PASSWORD varchar(40)
);
drop table if exists EMAIL
create table EMAIL(
USERID int(8),
EMAIL varchar(200),
foreign key (USERID) references USERS (ID)
);然后就报错了哪位达人能告诉我应该怎么写能达到预期的效果???
ID int(8) not null primary key,
USERNAME varchar(40),
PASSWORD varchar(40)
);create table EMAIL(
USERID int(8),
EMAIL varchar(200),
foreign key (USERID) references USERS (ID)
);可以看得出来USERS跟EMAIL表有主外键关联的关系。平时我们在建表的同时总有个习惯就是drop table if exists 表名
于是我就有了定向思维,分别在两张表前加了一句。变成了这样:
drop table if exists USERS
create table USERS(
ID int(8) not null primary key,
USERNAME varchar(40),
PASSWORD varchar(40)
);
drop table if exists EMAIL
create table EMAIL(
USERID int(8),
EMAIL varchar(200),
foreign key (USERID) references USERS (ID)
);然后就报错了哪位达人能告诉我应该怎么写能达到预期的效果???
解决方案 »
- 请教一个MYSQL字段类型问题
- mysql存储过程总是报1329错误 No data - zero rows fetched, selected, or processed
- 我有一个很复杂的存储过程A返回结果集,我想写另外的一个存储过程B调用A,存储过程B的作用是将A查询出来数据写数数据表,该如何写呢
- PL/SQL中难道不支持for和if的嵌套??
- 表行数据复制 mysql
- 哪位高手帮我看看这查询语句如何写?
- Access denied for user '[email protected]'(using password yes)错误
- 关于SQL查询的问题?急急急!
- unixODBC 和 MyODBC 之间的关系是什么?
- 求一条SQL 关于ON DUPLICATE KEY UPDATE
- 搜寻海量数据
- MYSQL 数据库部署问题,在线等。
Query OK, 0 rows affected (0.00 sec)mysql> drop table if exists USERS;
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> create table USERS(
-> ID int(8) not null primary key,
-> USERNAME varchar(40),
-> PASSWORD varchar(40)
-> );
Query OK, 0 rows affected (0.08 sec)mysql> drop table if exists EMAIL;
Query OK, 0 rows affected, 1 warning (0.00 sec)mysql> create table EMAIL(
-> USERID int(8),
-> EMAIL varchar(200),
-> foreign key (USERID) references USERS (ID)
-> );
Query OK, 0 rows affected (0.05 sec)mysql> drop table if exists USERS;
Query OK, 0 rows affected (0.05 sec)mysql> create table USERS(
-> ID int(8) not null primary key,
-> USERNAME varchar(40),
-> PASSWORD varchar(40)
-> );
Query OK, 0 rows affected (0.08 sec)mysql> drop table if exists EMAIL;
Query OK, 0 rows affected (0.02 sec)mysql> create table EMAIL(
-> USERID int(8),
-> EMAIL varchar(200),
-> foreign key (USERID) references USERS (ID)
-> );
Query OK, 0 rows affected (0.09 sec)mysql> set @@foreign_key_checks=on;
Query OK, 0 rows affected (0.00 sec)mysql>
http://topic.csdn.net/u/20090501/15/7548d251-aec2-4975-a9bf-ca09a5551ba5.html