SQL 判断表的存在,查表结构

--判断存在性

if exists (select * from sysobjects where id = object_id(N'[dbo].[T_Table]') and objectproperty(id,N'IsUserTable') = 1)
begin
 drop table T_OriginalStocks
end
create table T_Table(ID bigint identity(1,1) not null primary key,UserID bigint,StockNumber bigint,TradableStock bigint)on [primary]

--查表结构

select [name] from syscolumns where id = object_id(N'[dbo].[T_Table]') and objectproperty(id,N'IsUserTable') = 1

--创建临时表

if object_id('tempdb..#tempTable') is not null
begin
    drop table #tempTable
end

create table #tempTable(dsf int)

select * from  #tempTable


你可能感兴趣的:(sql,表结构,判断存在)