1. sql清空表數據的方法
一、sql清空表數據的三種方式:
1、truncate--刪除所有數據,保留表結構,不能撤銷還原
2、delete--是逐行刪除速度極慢,不適合大量數據刪除
3、drop--刪除表,數據和表結構一起刪除,快速
二、語法
truncate table 表名
delete from 表名
delete from 表名 where 列名="value "
drop form 表名
2. SQL語句中刪除表中數據的語句是什麼
刪除數據 delete Table where 欄位=''更新數據 update Table set 欄位='' where 欄位=''truncate drop都可刪除
TRUNCATE TABLE 刪除表中的所有行,而不記錄單個行刪除操作。
語法 TRUNCATE TABLE table_name 參數 table_name是要截斷的表的名稱或要刪除其全部行的表的名。
3. 清空某表的全部數據的SQL語句是不是這樣寫
是,也可以用DELETE FROM [表名] 。
以下是搜到的它們的區別:
TRUNCATE和DELETE有以下幾點區別
1、TRUNCATE在各種表上無論是大的還是小的都非常快。如果有ROLLBACK命令DELETE將被撤銷,而TRUNCATE則不會被撤銷。
2、TRUNCATE是一個DDL語言,向其他所有的DDL語言一樣,他將被隱式提交,不能對TRUNCATE使用ROLLBACK命令。
3、TRUNCATE將重新設置高水平線和所有的索引。在對整個表和索引進行完全瀏覽時,經過TRUNCATE操作後的表比DELETE操作後的表要快得多。
4、TRUNCATE不能觸發任何DELETE觸發器。
5、不能授予任何人清空他人的表的許可權。
6、當表被清空後表和表的索引講重新設置成初始大小,而delete則不能。
7、不能清空父表。
4. 清空表應該怎麼寫 SQL
清空所有數據:Truncate Table stu或者Delete stu。
清空第10條以後數據:Delete From Stu Where id Not In、
Select Top 10 id From stu Order By id。
5. sql怎麼刪除一個表中的所有數據
刪除表數據有兩種方法:delete和truncate。具體語句如下:
一、RUNCATE TABLE name :
刪除表中的所有行,而不記錄單個行刪除操作。在這個指令之下,表格中的資料會完全消失,可是表格本身會繼續存在。
TRUNCATE TABLE 的語法:TRUNCATE TABLE name ,參數 name 是要截斷的表的名稱或要刪除其全部行的表的名稱。
二、Delete from tablename where 1=1
1、delete語法:
DELETE FROM 表名稱 WHERE 列名稱 = 值。
2、刪除所有行:
可以在不刪除表的情況下刪除所有的行。這意味著表的結構、屬性和索引都是完整的:DELETE FROM table_name。
(5)sql清空數據的語句擴展閱讀:
truncate和delete的共同點及區別:
1、 truncate和 delete只刪除數據不刪除表的結構(定義) 。
2、delete語句是dml,這個操作會放到rollback segement中,事務提交之後才生效;如果有相應的trigger,執行的時候將被觸發。
truncate是ddl, 操作立即生效,原數據不放到rollback segment中,不能回滾. 操作不觸發trigger。
3、delete語句不影響表所佔用的extent, 高水線(high watermark)保持原位置不動 。truncate 語句預設情況下見空間釋放到 minextents個 extent,除非使用reuse storage; truncate會將高水線復位(回到最開始)。
4、速度,一般來說: truncate >delete 。
6. 如何一個SQL語句就刪除表中所有的數據
使用 TRUNCATE TABLE 刪除所有行
若要刪除表中的所有行,則 TRUNCATE TABLE 語句是一種快速、無日誌記錄的方法。該語句總是比不帶條件的 DELETE 語句要快,因為 DELETE 語句要記錄對每行的刪除操作,而 TRUNCATE TABLE 語句只記錄整個數據頁的釋放。TRUNCATE TABLE 語句立即釋放由該表的數據和索引佔用的所有空間。所有索引的分發頁也將釋放。
與 DELETE 語句相同,使用 TRUNCATE TABLE 清空的表的定義,同其索引和其它相關的對象一起仍保留在資料庫中。必須使用 DROP TABLE 語句才能除去表的定義。
TRUNCATE TABLE tablename
----------------------
TRUNCATE TABLE
刪除表中的所有行,而不記錄單個行刪除操作。語法TRUNCATE TABLE name參數name
是要截斷的表的名稱或要刪除其全部行的表的名稱。注釋TRUNCATE TABLE 在功能上與不帶 WHERE 子句的 DELETE 語句相同:二者均刪除表中的全部行。但 TRUNCATE TABLE 比 DELETE 速度快,且使用的系統和事務日誌資源少。
DELETE 語句每次刪除一行,並在事務日誌中為所刪除的每行記錄一項。TRUNCATE TABLE 通過釋放存儲表數據所用的數據頁來刪除數據,並且只在事務日誌中記錄頁的釋放。
TRUNCATE TABLE 刪除表中的所有行,但表結構及其列、約束、索引等保持不變。新行標識所用的計數值重置為該列的種子。如果想保留標識計數值,請改用 DELETE。如果要刪除表定義及其數據,請使用 DROP TABLE 語句。
對於由 FOREIGN KEY 約束引用的表,不能使用 TRUNCATE TABLE,而應使用不帶 WHERE 子句的 DELETE 語句。由於 TRUNCATE TABLE 不記錄在日誌中,所以它不能激活觸發器。
TRUNCATE TABLE 不能用於參與了索引視圖的表。示例下例刪除 authors 表中的所有數據。
7. 刪除資料庫的sql語句如何寫
1、drop database:資料庫名--刪除資料庫的。
2、drop table:表名--刪除表的。
3、delete from:表名--where條件--刪除數據的。
4、truncate table:表名--也是刪除資料庫的。
拓展資料
1、SQL即結構化查詢語言(Structured Query Language),是一種特殊目的的編程語言,是一種資料庫查詢和程序設計語言,用於存取數據以及查詢、更新和管理關系資料庫系統;同時也是資料庫腳本文件的擴展名。
2、SQL語句無論是種類還是數量都是繁多的,很多語句也是經常要用到的,SQL查詢語句就是一個典型的例子,無論是高級查詢還是低級查詢,SQL查詢語句的需求是最頻繁的。
8. 用SQL語句怎麼刪除表中的所有數據
從一個表中刪除數據,使用DELETE語句。從表中刪除所有行
DELETE FROMtable_name;
或DELETE * FROMtable_name;
或DELETE FROM Customers
WHERE cust_id = '10000006';
DELETE不需要列名和通配符,它是刪除整行而不是刪除列,要刪除指定的列,請使用update語句;並且DELETE語句從表中刪除行,甚至是刪除表中所有行,而不是刪除表本身。
如果想刪除表中的所有行,可以使用TRUNCATE TABLE語句,完成相同的工作,而速度更快。
(8)sql清空數據的語句擴展閱讀
drop直接刪掉表。
truncate刪除的是表中的數據,再插入數據時自增長的數據id又重新從1開始。
delete刪除表中數據,可以在後面添加where字句
(1)DELETE語句執行刪除操作的過程是每次從表中刪除一行,並且同時將該行的刪除操作作為事務記錄在日誌中保存以便進行進行回滾操作。TRUNCATE TABLE 則一次性地從表中刪除所有的數據並不把單獨的刪除操作記錄記入日誌保存,刪除行是不能恢復的。並且在刪除的過程中不會激活與表有關的刪除觸發器。執行速度快。
(2) 表和索引所佔空間。當表被TRUNCATE 後,這個表和索引所佔用的空間會恢復到初始大小,而DELETE操作不會減少表或索引所佔用的空間。drop語句將表所佔用的空間全釋放掉。
(3) 一般而言,drop > truncate > delete
(4) 應用范圍。TRUNCATE 只能對TABLE;DELETE可以是table和view
(5) TRUNCATE 和DELETE只刪除數據,而DROP則刪除整個表(結構和數據)。
(6) truncate與不帶where的delete :只刪除數據,而不刪除表的結構(定義)drop語句將刪除表的結構被依賴的約束(constrain),觸發器(trigger)索引(index);依賴於該表的存儲過程/函數將被保留,但其狀態會變為:invalid。
9. 如何一個SQL語句就刪除表中所有的數據
用SQL語句一次清空所有數據.找到了三種方法進行清空.使用的資料庫為MS SQL SERVER.(表之間不能有外鍵關系)
1.搜索出所有表名,構造為一條SQL語句
declare@trun_namevarchar(8000)
set@trun_name=''
select@trun_name=@trun_name+'truncatetable'+[name]+''fromsysobjectswherextype='U'andstatus>0
exec(@trun_name)
該方法適合表不是非常多的情況,否則表數量過多,超過字元串的長度,不能進行完全清理.
2.利用游標清理所有表
declare@trun_namevarchar(50)
declarename_cursorcursorfor
select'truncatetable'+namefromsysobjectswherextype='U'andstatus>0
openname_cursor
fetchnextfromname_cursorinto@trun_name
while@@FETCH_STATUS=0
begin
exec(@trun_name)
print'truncatedtable'+@trun_name
fetchnextfromname_cursorinto@trun_name
end
closename_cursor
deallocatename_cursor
這是我自己構造的,可以做為存儲過程調用, 能夠一次清空所有表的數據,並且還可以進行有選擇的清空表.
3.利用微軟未公開的存儲過程(前提是使用sql server 2005以上版本)
execsp_msforeachtable"truncatetable?"
--刪除當前資料庫所有表中的數據sp_MSforeachtable@command1='Deletefrom?'sp_MSforeachtable@command1="TRUNCATETABLE?"
該方法可以一次清空所有表,但不能加過濾條件.
引:csdn,blog.csdn.net/feiji323/article/details/5669775
10. SQL清除語句
CREATE SNAPSHOT [schema.]snapshot
[ [PCTFREE integer] [PCTUSED integer]
[INITRANS integer] [MAXTRANS integer]
[TABLESPACE tablespace]
[STORAGE storage_clause]
[ USING INDEX [ PCTFREE integer | TABLESPACE tablespace
| INITTRANS integer | MAXTRANS integer
| STORAGE storage_clause ] ...
| [CLUSTER cluster (column [, column]...)] ]
[ REFRESH [FAST | COMPLETE | FORCE] [START WITH date] [NEXT date]]
AS subquery
schema
is the schema to contain the snapshot. If you omit schema, Oracle
creates the snapshot in your schema.
snapshot
is the name of the snapshot to be created.
Oracle chooses names for the table, views, and index used to
maintain the snapshot by prefixing the snapshot name. To limit
these names to 30 bytes and allow them to contain the entire
snapshot name, Oracle Corporation recommends that you limit your
snapshot names to 23 bytes.
PCTFREE
PCTUSED
INITRANS
MAXTRANS
establishes values for these parameters for the internal table
Oracle uses to maintain the snapshot's data.
TABLESPACE
specifies the tablespace in which the snapshot is to be created. If
you omit this option, Oracle creates the snapshot in the default
tablespace of the owner of the snapshot's schema.
STORAGE
establishes storage characteristics for the table Oracle uses to
maintain the snapshot's data.
USING INDEX
specifies the storage characteristics for the index on a simple
snapshot. If the USING INDEX clause not specified, the index is
create with the same tablespace and storage parameters as the
snapshot.
CLUSTER
creates the snapshot as part of the specified cluster. Since a
clustered snapshot uses the cluster's space allocation, do not use
the PCTFREE, PCTUSED, INITRANS, or MAXTRANS parameters, the
TABLESPACE option, or the STORAGE clause in conjunction with the
CLUSTER option.
REFRESH
specifies how and when Oracle automatically refreshes the snapshot:
FAST
specifies a fast refresh, or a refresh using only the
updated data stored in the snapshot log associated
with the master table.
COMPLETE
specifies a complete refresh, or a refresh that re-
executes the snapshot's query.
FORCE
specifies a fast refresh if one is possible or
complete refresh if a fast refresh is not possible.
Oracle decides whether a fast refresh is possible at
refresh time.
If you omit the FAST, COMPLETE, and FORCE options,
Oracle uses FORCE by default.
START WITH
specifies a date expression for the first automatic
refresh time.
NEXT
specifies a date expression for calculating the
interval between automatic refreshes.
Both the START WITH and NEXT values must evaluate to a time in the
future. If you omit the START WITH value, Oracle determines the
first automatic refresh time by evaluating the NEXT expression when
you create the snapshot. If you specify a START WITH value but omit
the NEXT value, Oracle refreshes the snapshot only once. If you
omit both the START WITH and NEXT values or if you omit the REFRESH
clause entirely, Oracle does not automatically refresh the snapshot.
AS subquery
specifies the snapshot query. When you create the snapshot, Oracle
executes this query and places the results in the snapshot. The
select list can contain up to 253 expressions. A snapshot query is
subject to the same restrictions as a view query.
PREREQUISITES:
To create a snapshot in your own schema, you must have CREATE
SNAPSHOT system privilege. To create a snapshot in another user's
schema, you must have CREATE ANY SNAPSHOT system privilege.
Before a snapshot can be created, the user SYS must run the SQL
script DBMSSNAP.SQL on both the database to contain the snapshot and
the database(s) containing the tables and views of the snapshot's
query. This script creates the package SNAPSHOT which contains both
public and private stored proceres used for refreshing the
snapshot and purging the snapshot log. The exact name and location
of this script may vary depending on your operating system.
When you create a snapshot, Oracle creates a table, two views, and
an index in the schema of the snapshot. Oracle uses these objects
to maintain the snapshot's data. You must have the privileges
necessary to create these objects. For information on these
privileges, see the CREATE TABLE, CREATE VIEW, and CREATE INDEX
commands.
The owner of the schema containing the snapshot must have either
space quota on the tablespace to contain the snapshot or UNLIMITED
TABLESPACE system privilege. Also, both you (the creator) and the
owner must also have the privileges necessary to issue the
snapshot's query.
To create a snapshot, you must be using Oracle with the proceral
option. To create a snapshot on a remote table or view, you must
also be using the distributed option.