Sql Server 能这样创建表吗

来源:百度知道 编辑:UC知道 时间:2024/06/08 19:21:29
if exists (select *from sysobjects where name = 'DatabaseInfo')
drop table DatabaseInfo
declare @idvalue int
set @idvalue=DATEPART(year, GETDATE())*1000
select @idvalue

create table DatabaseInfo
(
BID int identity(@idvalue,1) not null, --编号根据每年的年份生成ID号
Bname varchar(8) not null --姓名

为什么行不通,
哪位大哥大姐能帮帮我实现一下,小弟在此感激不尽
如果要实现上面的功能那要怎么做呢,

if exists (select * from dbo.sysobjects where name = 'DatabaseInfo')
drop table DatabaseInfo
declare @idvalue int
set @idvalue=DATEPART(year, GETDATE())*1000
select @idvalue

create table DatabaseInfo
(
BID int not null, --编号根据每年的年份生成ID号
Bname varchar(8) not null --姓名
)
insert into DatabaseInfo(BID,Bname)
VALUES (@idvalue + 1,'名字')

这个编号需要执行存储过程或程序判断付+1的值,从建表中应该难以完成

建表时好像不能用@

set @idvalue=DATEPART(year, GETDATE())*1000??
要做什么??