truncate

How to empty a SQL database?

无人久伴 提交于 2019-11-30 03:18:06
I'm searching for a simple way to delete all data from a database and keep the structure (table, relationship, etc...). I using postgreSQL but I think, if there a command to do that, it's not specific to postgres. Thanks, Damien Adam Matan Dump the schema using pg_dump . drop the database, recreate it and load the schema. Dump you database schema (the -s tag) to a file: pg_dump -s -f db.dump DB-NAME Delete the database: dropdb DB-NAME Recreate it: createdb DB-NAME Restore the schema only: pg_restore db.dump > psql DB-NAME This should work on PostgreSQL; Other DBMS might have their own tools

Bulk delete (truncate vs delete)

我的梦境 提交于 2019-11-30 03:11:10
问题 We have a table with a 150+ million records. We need to clear/delete all rows. Delete operation would take forever due to it writing to the t-logs and we cannot change our recovery model for the whole DB. We have tested the truncate table option. What we realized that truncate deallocates pages from the table, and if I am not wrong makes them available for reuse but doesn't shrink the db automatically. So, if we want to reduce the DB size, we really would need to do run the shrink db command

Truncate date to fiscal year

◇◆丶佛笑我妖孽 提交于 2019-11-30 02:29:43
问题 The following database view truncates the date to the fiscal year (April 1st): CREATE OR REPLACE VIEW FISCAL_YEAR_VW AS SELECT CASE WHEN to_number(to_char(SYSDATE, 'MM')) < 4 THEN to_date('1-APR-'||to_char(add_months(SYSDATE, -12), 'YYYY'), 'dd-MON-yyyy') ELSE to_date('1-APR-'||to_char(SYSDATE, 'YYYY'), 'dd-MON-yyyy') END AS fiscal_year FROM dual; This allows us to calculate the current fiscal year based on today's date. How can this calculation be simplified or optimized? 回答1: ADD_MONTHS

Rails truncate with a 'read more' toggle

前提是你 提交于 2019-11-30 01:51:42
问题 I have a paragraph that I want truncated with the option of clicking "read more" and have it slide open with the rest of the content. The content is coming from a database field. Here's what I have for the truncate: <%= truncate(@major.glance, :length => 250, :omission => '... Read More')%> I can't seem to find a way to do this with data pulled from a database. I see a lot of examples using the full text with the text you want to hide in a separate div tag. But, since this content is coming

Truncating the end of a string in R after a character that can be present zero or more times

荒凉一梦 提交于 2019-11-29 14:09:16
问题 I have the following data: temp<-c("AIR BAGS:FRONTAL" ,"SERVICE BRAKES HYDRAULIC:ANTILOCK", "PARKING BRAKE:CONVENTIONAL", "SEATS:FRONT ASSEMBLY:POWER ADJUST", "POWER TRAIN:AUTOMATIC TRANSMISSION", "SUSPENSION", "ENGINE AND ENGINE COOLING:ENGINE", "SERVICE BRAKES HYDRAULIC:ANTILOCK", "SUSPENSION:FRONT", "ENGINE AND ENGINE COOLING:ENGINE", "VISIBILITY:WINDSHIELD WIPER/WASHER:LINKAGES") I would like to create a new vector that retains only the text before the first ":" in the cases where a ":"

Mysql TRUNCATE 和 DELETE 清空表操作的区别

强颜欢笑 提交于 2019-11-29 12:12:03
本质: TRUNCATE 是 DDL(数据定义语言), DELETE 是 DML(数据操作语言) 所以 truncate 操作是无法在事务中回滚的 ,但 delete 在事务上下文中在 commit 前是可以回滚 常见的 DDL 命令还有 CREATE/ALTER/DROP ,这些操作 在事务上下文中都是无法回滚的 ,你可认为它们自带提交 1、TRUNCATE TABLE `tabName` | 在任何引擎中都可以快速清空表 # 清空表 无法回滚 重置表高度和水平线(即 auto_increment = 1) TRUNCATE TABLE `tabName`; 在InnoDB引擎中清空表 TRUNCATE 要比 DELETE 高效,因为 DELETE 命令在 InnoDB 引擎中是一行行的删除(在 MyISAM中两者应该不分上下,都是直接将表清空后重新创建一个新表),而 TRUNCATE 则是直接将表删掉重新创建一个新的,同时重置表水平线,自增等特性都将复位 2、 DELETE FROM `tabName` [ WHERE conditions ......] | 可以定位删除 可以清空表 事务上下文可回退 不重置表高度及水平线 # 清空表 事务上下文可回滚 不重置表高度和水平线 DELETE FROM `tabName`; MyISAM引擎中为清空重建表

MySql - Create Table If Not Exists Else Truncate?

穿精又带淫゛_ 提交于 2019-11-29 11:06:22
问题 Here is the updated question: the current query is doing something like: $sql1 = "TRUNCATE TABLE fubar"; $sql2 = "CREATE TEMPORARY TABLE IF NOT EXISTS fubar SELECT id, name FROM barfu"; The first time the method containing this is run, it generates an error message on the truncate since the table doesn't exist yet. Is my only option to do the CREATE TABLE , run the TRUNCATE TABLE , and then fill the table? (3 separate queries) original question was: I've been having a hard time trying to

SQL Query to truncate table in IBM DB2

牧云@^-^@ 提交于 2019-11-29 10:27:31
Can any one give me the syntax to truncate a table in IBM DB2. I m running the following command: truncate table tableName immediate; The eror is DB2 SQLCODE=-104, SQLSTATE=42601, SQLERRMC=table;truncate ;JOIN , DRIVER=3.50.152 Message: An unexpected token "table" was found following "truncate ". Expected tokens may include: "JOIN ".. SQLCODE=-104, SQLSTATE=42601, DRIVER=3.50.152 The syntax matches the one specified in the reference docs of IBM : http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.sqlref/db2z_sql_truncate.htm Nick Vallely There is a great

Automatic TRUNCATE table in MySQL [closed]

我怕爱的太早我们不能终老 提交于 2019-11-29 02:27:43
I am looking for a way to automatically clean table in MySQL once per day. Is this possible without using cron? The best solution would be a trigger, but any solution is applicable. One option is MySQL's EVENT scheduler: CREATE EVENT e_daily ON SCHEDULE EVERY 1 DAY STARTS '2014-02-23 05:00:00' -- Time to start COMMENT 'Descriptive comment' DO TRUNCATE yourtable; How to enable event scheduler 来源: https://stackoverflow.com/questions/21956291/automatic-truncate-table-in-mysql

Using hibernate/hql to truncate a table?

与世无争的帅哥 提交于 2019-11-29 02:11:53
问题 What is the recommended way to truncate a table using hibernate/hql? I've tried this: Query query = session.createQuery("truncate table MyTable"); query.executeUpdate(); But it didn't work (truncate doesn't seem do be documented anywhere in hql...) 回答1: I guess an horrible way of doing it would be deleting all. public int hqlTruncate(String myTable){ String hql = String.format("delete from %s",myTable); Query query = session.createQuery(hql); return query.executeUpdate(); } 回答2: You can use