【转SQL】truncate:清空表中数据

清除一个表中的所有数据:

(1)一种方式是用 DROP TABLE 指令,它会使整个表格消失,而无法再被用了。

(2)一种方式就是运用 TRUNCATE TABLE 的指令。在这个指令之下,表格中的数据会完全消失,但会保留表结构,不能撤消还原。 

TRUNCATE TABLE 的语法如下:

​TRUNCATE TABLE "表格名";

【P.S.】与delete * from xxx的区别

truncate:会清空表中所有的数据,速度快,不可回滚;实质是删除整张表包括数据再重新创建表。  

delete:逐行删除数据,每步删除都是有日志记录的,可以回滚数据;实质是逐行删除表中的数据。

SET FOREIGN_KEY_CHECKS=0;
 
-- ----------------------------
-- Table structure for medical_list
-- ----------------------------
DROP TABLE IF EXISTS `medical_list`;
CREATE TABLE `medical_list` (
  `id` bigint(20) NOT NULL,
  `name` longtext,
  `county_id` bigint(20) DEFAULT NULL,
  `street_office_id` bigint(20) DEFAULT NULL,
  `longitude` double DEFAULT NULL,
  `latitude` double DEFAULT NULL,
  `type` char(255) DEFAULT NULL,
  `parent_id` bigint(20) DEFAULT NULL,
  `max_popu` int(11) DEFAULT NULL,
  `popu_list` longtext,
  `popu` int(11) DEFAULT NULL,
  `building_id` bigint(20) DEFAULT NULL,
  `gridx` int(10) DEFAULT NULL,
  `gridy` int(10) DEFAULT NULL,
  `lRegionID` int(10) DEFAULT NULL,
  `RegionID_lon` double DEFAULT NULL,
  `RegionID_lat` double DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;


 

发布了1976 篇原创文章 · 获赞 3818 · 访问量 1006万+

猜你喜欢

转载自blog.csdn.net/zhongguomao/article/details/103150851