mysql用一个数据库不同的表,如何使其中一个列和两个表产生关联?比如表 a 和 表 b,都有一个 id列如何能够方便的是a,b两个表通过id列进行关联比如在a表中插入一行,相应b也多了一行查找啊,删除,修改也可以实现?
解决方案 »
- sql注入漏洞最好是过滤掉“'”,但是如果内容中需要'怎么办呢?
- 请解释 select * from tt t where not exists(select 1 from tt where 姓名=t.姓名 and 薪资>t.薪资 )
- 如何复制表
- sql语句请教
- 批语句中使用RAISERROR抛出异常,应用程序不能捕捉
- 桌面数据库的数据发布问题
- 关于MSSQL Server DTS(非一般的问题)
- 请问用什么办法本机查询速为约4秒的语句加快速度?
- 小问题!SQL上能否编程???
- 帮帮我,关于在JBuilder中连接MS SQL Server2000的问题!!!???
- sql2008邮件服务器设置
- 请教 sql语句。。
-- 1. create tables :Drop table if exists t_a;
create table t_a
(
id mediumint(9) not null default '0',
data varchar(50) default null,
primary key (id)
) ;Drop table if exists t_b;
create table t_b
(
id mediumint(9) not null default '0',
data varchar(50) default null,
primary key (id)
);-- 2 . create trigger:Drop trigger if exists tg_T_a_Insert;
delimiter //
create trigger tg_T_a_Insert
after insert on t_a
for each row
begin
insert into t_b (id,data) values (new.id,new.data);
end;
//
delimiter ;-- 3. Insert:
insert into t_a (id,data) values (1,'data1'),(2,'data2');-- 4. Query:
select * from t_a;
select * from t_b;写进sql.sql文件
mysql> source d:/sql.sql
Query OK, 0 rows affected (0.06 sec)Query OK, 0 rows affected (0.28 sec)Query OK, 0 rows affected (0.03 sec)Query OK, 0 rows affected (0.19 sec)Query OK, 0 rows affected, 1 warning (0.00 sec)Query OK, 0 rows affected (0.03 sec)Query OK, 2 rows affected (0.06 sec)
Records: 2 Duplicates: 0 Warnings: 0+----+-------+
| id | data |
+----+-------+
| 1 | data1 |
| 2 | data2 |
+----+-------+
2 rows in set (0.00 sec)+----+-------+
| id | data |
+----+-------+
| 1 | data1 |
| 2 | data2 |
+----+-------+
2 rows in set (0.00 sec)