mysql建立临时表

1、临时表再断开于mysql的连接后系统会自动删除临时表中的数据,但是这只限于用下面语句建立的表:
A. 定义字段(注意:不同于mssql,在表名前加上#或@, 这里是加上 temporary.)
  create temporary  table tmp_table (

      idno int not null,
      name varchar(10) not null
  )
B. 可以直接将查询结果导入临时表 (我觉得这种方法很有用, 特别对多表关联, 可以直接把查询出来的放在临时表,再读取)

  create temporary table tmp_table select * from table_name


2、另外mysql也允许你在内存中直接创建临时表,因为是在内存中所有速度会很快,语法如下:
  create temporary table tmp_table (

     idno int not null,
     name varchar(10) not null

  ) TYPE = HEAP

注意: 只有断开数据库连接才会被清空数据,在一个数据库连接里面发行多次sql的话系统是不会自动清空临时表数据的。

猜你喜欢

转载自ware.iteye.com/blog/1442507