sql刪除數據庫所有表
1.搜索出所有表名,構造為一條SQL語句 declare @trun_name varchar(8000)
set @trun_name=''
select @trun_name=@trun_name + 'truncate table ' + [name] + ' ' from sysobjects where xtype='U' and status > 0
exec (@trun_name)該方法適合表不是非常多的情況,否則表數量過多,超過字符串的長度,不能進行完全清理. 2.利用游標清理所有表 declare @trun_name varchar(50)
declare name_cursor cursor for
select 'truncate table ' + name from sysobjects where xtype='U' and status > 0
open name_cursor
fetch next from name_cursor into @trun_name
while @@FETCH_STATUS = 0
begin
exec (@trun_name)
print 'truncated table ' + @trun_name
fetch next from name_cursor into @trun_name
end
close name_cursor
deallocate name_cursor
這是我自己構造的,可以做為存儲過程調用, 能夠一次清空所有表的數據,并且還可以進行有選擇的清空表. 3.利用微軟未公開的存儲過程 exec sp_msforeachtable "truncate table ?"
怎么用SQL語句刪除數據庫中多個文件
REMOVE FILE 只有在文件為空時才能刪除。
正常操作步驟:
以下操作在查詢分析器上執行即可:
--轉到要處理的數據庫:
use 庫名
go
--查看該庫所有的文件:
select [name],[filename] from sysfiles
go
--對指定的文件進行數據移除:
dbcc shrinkfile (上面查詢得到的“邏輯文件名”(即Name那列), EMPTYFILE)
go
--將一定移除了數據的指定文件刪除:
ALTER DATABASE 庫名 REMOVE FILE 上面查詢得到的“邏輯文件名”
Go
mysql數據庫刪除數據語句怎么寫
方法/步驟
查詢數據:select * from xxx;
例子:
(1)select id,username,password from t_user;
(2)select id,username,password,gender from t_user where gender = '男';
(3)select id,username,password,gender from t_user where gender is null;
添加數據:insert xxx(id, username) values(xx, "xxx");
例子:
insert into t_user(id, username) values(10, "hehehe");
insert into t_user(id, gender, username, age, password) values(15, '男', 'shihu', 18, '123456');
insert into t_user values(16, 'benladeng', '123456', '拉登', 'nan', 18);
修改數據:update tablename set xx=xx,xxx=xx where xxx=xxx and xxx=xxx;
刪除數據:delete from tablename where xx=xxx and xxx = xxx or xxx = xxx;
DQL數據查詢語言
連接查詢
左外連接
select
* ename,
*,
* dname
from
t_employee e left outer join t_department d
on
*_id = *
6
設置數據庫可以被其他計算機連接
打開名為mysql的數據庫 --> user表 -->; 將root的host改為% -->; 提交 -->; 重啟mysql服務即可。
如何批量刪除數據庫里某個表里的多條記錄
1、首先我們打開SQL Database Studio。
2、然后我們點擊展開數據庫連接和數據庫。
3、然后我們展開已有的表。
4、然后我們雙擊要刪除記錄的表,進入表數據操作界面。
5、然后我們選定要刪除的記錄,點擊【delete selected rows】。
6、此時顯示將刪除的記錄,點擊【save to db】。