標籤:刪除 dhx into wce vpn htm from jna mba
sql server 中暫存資料表與資料表的區別
1、如何判斷暫存資料表和資料表已產生
--如何判斷暫存資料表是否已建立---if exists(select * from tempdb..sysobjects where id=object_id(‘tempdb..#Temp_Student‘)) begin print ‘存在暫存資料表‘; endelse begin print ‘不存在暫存資料表‘; end--如何判斷資料表是否已建立---if exists(select * from sys.tables where name=‘Data_Student‘) begin print ‘存在資料表‘; endelse begin print ‘不存在資料表‘; end
其中,暫存資料表建立後預設在tempdb(臨時資料庫中)的sysobjects中,而資料表建立在當前資料庫的sys.tables中
2、如何建立暫存資料表和資料表
當我們檢查到暫存資料表、資料表不存在時,一般進行建立暫存資料表、資料表;存在時,可進行刪除或清空資料
--1、如何判斷暫存資料表是否已建立---if exists(select * from tempdb..sysobjects where id=object_id(‘tempdb..#Temp_Student‘)) begin --print ‘存在暫存資料表‘; --刪除暫存資料表(包括表結構)-- --drop table #Temp_Student --刪除暫存資料表(不包括表結構)-- truncate table #Temp_Student endelse begin --print ‘不存在暫存資料表‘; create table #Temp_Student ( Uid int identity(1,1) primary key, Age int not null, Name varchar(20) not null, ) end --2、如何判斷資料表是否已建立---if exists(select * from sys.tables where name=‘Data_Student‘) begin --print ‘存在資料表‘; --刪除資料表(包括表結構)-- --drop table Data_Student --刪除資料表(不包括表結構)-- truncate table Data_Student endelse begin --print ‘不存在資料表‘; --不存在時,建立資料表-- create table Data_Student ( Uid int identity(1,1) primary key, Age int not null, Name varchar(20) not null, ) end
3、如何添加暫存資料表和資料表的資料
-----3、如何插入資料------1)插入資料到暫存資料表---insert into #Temp_Student(Age,Name) values(21,‘張三‘),(22,‘李四‘) --2)插入資料到資料表---insert into Data_Student(Age,Name) values(23,‘王五‘),(24,‘趙六‘)
4、如何查詢暫存資料表和資料表資料
-----4、如何查詢資料------- --1)查詢暫存資料表--select * from #Temp_Student--2)查詢暫存資料表--select * from Data_Student
5、查詢後結果
sql Server中暫存資料表與資料表的區別