mssql 2000 按月分割槽表 來於網路

2021-04-30 00:39:39 字數 1633 閱讀 6119

--建立

create procedure sp_records  

@year nvarchar(4)  

as  

declare @count int,  

@yearmonth nvarchar(6),  

@month nvarchar(2)  

set @count = 0  

while @count <12  

begin  

set @count = @count + 1  

if @count <10 set @month = '0'+convert(nvarchar(1),@count)  

else set @month = convert(nvarchar(2),@count)  

set @yearmonth = @year+@month  

if   object_id ('..records'+@yearmonth+'') is null  

exec(  

'create table records'+@yearmonth+'(  

-- [id] [bigint] identity (1, 1) not null ,

[id] [varchar] (50) not null ,     

[rad_id] [int] not null ,  

[ip] [varchar] (50) not null ,    

[addtime] [varchar] (20) not null  

check ([addtime] between '''+@year+'-'+@month+'-01 00:00:00'' and '''+@year+'-'+@month+'-31 23:59:59''),  

constraint [pk_records'+@yearmonth+'] primary key  

(  [id],  

[addtime]

)   on [primary]  

) on [primary]'  

)  end  

declare @view varchar(8000) 

set @view = '' 

select @view = @view + ' union all select * from [dbo].' + name 

from sysobjects 

where name like 'records[0-9][0-9][0-9][0-9][0-1][0-9]' 

and objectproperty(id,'isusertable')=1 

set @view = stuff(@view, 1, 11, '') 

if object_id('v_records') is null 

set @view = 'create view [v_records] as ' + @view 

else 

set @view = 'alter view [v_records] as ' + @view 

exec(@view) 

print (@view) 

go --執行

exec sp_records @year='2009'

MSSQL2000資料型別

長度 定長變長 變長時該長度為最大長度 定長時該長度一定要滿足該長度的大小。字元型別中的var是變長的 字元 位元組 統一編碼用雙位元組結構來儲存每個字元,而不是用單位元組 普通文字中的情況 sql字元類的資料型別中有個n開頭的型別是統一編碼的 mssql中要指定長度的資料型別有char,varch...

Ms sql 2000 動態組合條件

select a.id,a.typename,a.code,a.content,a.buildin,a.parentid,b.content categorydisplayname,b.buildin categorybuildin,b.reftablename from code a left j...

按照姓名分組 MS SQL2000

declare t table name varchar 20 insert into t select 全曉輝 union all select 全市的 union all select 第三代 union all select 撒地方 union all select 撒旦 select max...