create procedure get_tableinfo as
create table #tablespaceinfo --建立結果儲存表
(nameinfo varchar(50) ,
rowsinfo int , reserved varchar(20) ,
datainfo varchar(20) ,
index_size varchar(20) ,
unused varchar(20) )
declare @tablename varchar(255) --表名稱
declare @cmdsql varchar(500)
declare info_cursor cursor for
select o.name
from dbo.sysobjects o where objectproperty(o.id, n'istable') = 1
and o.name not like n'#%%' order by o.name
open info_cursor
fetch next from info_cursor
into @tablename
while @@fetch_status = 0
begin
if exists (select * from dbo.sysobjects where id = object_id(@tablename) and objectproperty(id, n'isusertable') = 1)
execute sp_executesql
n'insert into #tablespaceinfo exec sp_spaceused @tbname',
n'@tbname
varchar(255)',
@tbname = @tablename
fetch next from info_cursor
into @tablename
end
close info_cursor
deallocate info_cursor
select * from #tablespaceinfo order by rowsinfo desc
go
SQL語句,查詢資料庫裡是否存在某個表
今天在搞乙個資料庫語句,因為老大要求,每個月自動生成乙個表,但是,我要做判斷,如果資料庫已經有這個表了,就不用建立了,但是我不知道怎麼查,在朋友的幫助下,找到這個兩個語句,和大家分享一下.select count 1 from sys.objects where name 表名 select obj...
SQL語句,查詢資料庫裡是否存在某個表
今天在搞乙個資料庫語句,因為老大要求,每個月自動生成乙個表,但是,我要做判斷,如果資料庫已經有這個表了,就不用建立了,但是我不知道怎麼查,在朋友的幫助下,找到這個兩個語句,和大家分享一下.select count 1 from sys.objects where name 表名 select obj...
SQL語句,查詢資料庫裡是否存在某個表
select count 1 from sys.objects where name 表名 select objectproperty object id 表名 isusertable 這兩個sql語句都是查詢資料庫裡頭是否存在某個表的語句,以後都是查詢表裡某個列,第一次查詢資料庫是否有某個表,原來...