sql 创建时间函数

来源:互联网 发布:js控制浏览器缩放比例 编辑:程序博客网 时间:2024/04/28 14:18

//视图

create view time as select dt=convert(char(4),getdate(),12) go

//函数

create function dbo.time_fun() returns char(8) as begin declare @dt char(4),@r char(8) select @dt=dt from time select @r=@dt+right(10001+min(userid),4) from(select userid=right(userid,4) from users with(xlock,paglock) where userid like @dt+'%' union all select 0)a where not exists(select * from users with(xlock,paglock) where userid like @dt+'%' and userid=@dt+right(10001+a.userid,4)) return(@r) end

//表

create table users(userID char(8) default dbo.time_fun() primary key,username varchar(20) not null unique,password varchar(10) not null,realname varchar(20) not null,sex char(2) check(sex in('男','女')),identifyName varchAr(20) not null,identifyNO varchar(18) not null,eduation varchar(20) null,provicy varchar(20) not null,address varchar(30),stempNo char(6),mobileTel char(11) NULL,homeTel varchar(9) null,Email varchar(20) null,passwordQuestion varchar(50) not null,passwordAnswer varchar(50) not null,notice text null

 

原创粉丝点击