社区
MS-SQL Server
帖子详情
datatime和smalldatetime有什么区别?
ytzyf
2003-08-22 07:37:16
请举例子解释一下,谢谢:)
...全文
77
2
打赏
收藏
datatime和smalldatetime有什么区别?
请举例子解释一下,谢谢:)
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
2 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
nboys
2003-08-22
打赏
举报
回复
smalldatetime
从 1900 年 1 月 1 日到 2079 年 6 月 6 日的日期和时间数据精确到分钟。29.998 秒或更低的 smalldatetime 值向下舍入为最接近的分钟,29.999 秒或更高的 smalldatetime 值向上舍入为最接近的分钟。
datetime
从 1753 年 1 月 1 日到 9999 年 12 月 31 日的日期和时间数据,精确度为百分之三秒(等于 3.33 毫秒或 0.00333 秒)。
hjb111
2003-08-22
打赏
举报
回复
日期和时间数据
日期和时间数据由有效的日期或时间组成。例如,有效日期和时间数据既包括"4/01/98 12:15:00:00:00 PM",也包括"1:28:29:15:01 AM 8/17/98"。在 Microsoft® SQL Server™ 2000 中,日期和时间数据使用 datetime 和 smalldatetime 数据类型存储。使用 datetime 数据类型存储从 1753 年 1 月 1 日至 9999 年 12 月 31 日的日期(每个数值要求 8 个字节的存储空间)。使用 smalldatetime 数据类型存储从 1900 年 1 月 1 日至 2079 年 6 月 6 日的日期(每个数值要求 4 个字节的存储空间)。
Sql中将da
te
time
转换成字符串的方法(CONVERT)
一、回顾一下CONVERT()的语法格式:CONVERT (<
data
>[ length ], <expression> [, style])二、这里注重说明一下style的含义:style 是将
DATA
TIME
和
SMAL
LDA
TE
TIME
数据转换为字符串时所选用的由SQL Server 系统提供的转换样式编号,不同的样式编号有不同的输出格式;一般在时间类型(da
te
time
,
smal
lda
te
time
)与字符串类型(nchar,nvarchar,char,varchar)相互转换的时候才用到.三、下表是SQL Server 系统提供的转换样式编号: 不带世纪数位 (yy
数据库表ERP表参考。仅供参考
--------语法 --建立视图 --if exists(select * from sysobjects where name='视图名') -- drop view 视图名 --go --crea
te
view 视图名 --as --select 字段名 from 表名 [条件] --go --主外健约束语句没有执行 use T90ERP go --***********人力资源 --部门表:Depet if exists(select * from sysobjects where name='Depet') drop table Depet go crea
te
table Depet ( dept_id Int primary key identity(1,1) not null, --部门编号 主键,自增 dept_name Varchar(20) not null --部门名称 ) ----约束 --al
te
r table Depet add constraint UQ_dept_name unique (dept_name) go --职位表:Post if exists(select * from sysobjects where name='Post') drop table Post go crea
te
table Post ( Post_id Int primary key identity(1,1) not null, --职位编号 主键 自增 Post_name Varchar(50) not null, --职位名称 唯一 Post_money Money not null, --职位工资 Dept_id int not null --部门编号 外 Int 级联删除 ) ----约束 --al
te
r table post add constraint UQ_post_name unique (post_name) al
te
r table post add constraint FK_post_deptId foreign key(post_deptId) references depet(dept_id) go --员工信息表:Employee if exists(select * from sysobjects where name='Employee') drop table Employee go crea
te
table Employee ( Emp_id Int primary key identity(1,1) not null, --员工信息编号 主键,自增 Emp_number Varchar(50) not null, --员工工号 唯一 Emp_postId Int not null, --职位编号 外键 级联删除 Emp_hire Da
te
time
not null, --录用时间 Emp_sta
te
Bit not null, --状态 默认1 (1在职/0离职) ) ----约束 --al
te
r table Employee add constraint UQ_emp_number unique (emp_number) al
te
r table Employee add constraint FK_emp_postId foreign key (emp_postId) references post(post_id) --al
te
r table Employee add constraint DF_emp_sta
te
default(1) for emp_sta
te
go --简历表:Resume if exists(select * from sysobjects where name='Resume') drop table Resume go crea
te
table Resume ( Res_id Int primary key identity(1,1) not null, --职员信息ID 主键 非空自增 Int Emp_id Int not null, --职员ID 外键 Res_name Varchar(50) not null, --真实姓名 Res_englishname Varchar(50) null, --英文名 空 Res_idcard Varchar(19) not null, --身份证号 唯一索引 只有18位数字或18位数字加X Res_sex bit not null, --性别 默认1 男 只有男和女两种 Res_bornDa
te
da
te
time
not null, --出生年月 Res_nativeplace varchar(50) not null, --籍贯 Res_nation Varchar(50) not null, --民族 默认汉族 Res_health
te
xt null, --健康状况 空 默认健康 Res_diploma Varchar(50) not null, --学历 Res_address Varchar(50) null, --联系地址 空,默认地址不详 Res_
Te
l Varchar(50) not null, --电话 只能是11为数字 Res_photo image null --照片 空 ) ----约束 al
te
r table Resume add constraint FK_res_empid foreign key (res_empid) references Employee(emp_id) --al
te
r table Resume add constraint UQ_res_idcard unique (res_idcard) --al
te
r table Resume add constraint CK_res_idcard check (res_idcard like '[1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9] --[1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9]' or res_idcard like '[1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9] --[1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9][1-9]X') --al
te
r table Resume add constraint DF_res_sex default (1) for res_sex --al
te
r table Resume add constraint CK_res_sex check(res_sex=1 or res_sex=0) --al
te
r table Resume add constraint DF_res_nation default ('汉族') for res_nation --al
te
r table Resume add constraint DF_res_health default ('健康') for res_health --al
te
r table Resume add constraint DF_res_health defatult(1) for res_health --al
te
r table Resume add constraint DF_res_address default ('地址不详') for res_address --al
te
r table Resume add constraint CK_res_
te
l check(len(res_
te
l)=11) go --考勤类型表:CheckType if exists(select * from sysobjects where name='CheckType') drop table CheckType crea
te
table CheckType ( Checkt_id int primary key identity(1,1) not null, --考勤类型 主键 自增 Int Checkt_name varchar(50) not null --考勤名称(干什么) Varchar(50) ) go --考勤表:Check if exists(select * from sysobjects where name='CheckInfo') drop table CheckInfo crea
te
table CheckInfo ( Check_id int primary key identity(1,1) not null, --考勤id 主键 自增 Int Emp_id int not null, --员工id 外键 Int Check_hire da
te
time
not null, --考勤开始时间 开始时间必须 Da
te
time
Check_end da
te
time
not null, --考勤结束时间 要在结束时间之前
Data
time
Checkt_id int not null, --考勤类型 外键 Int Check_g
time
int not null, --工休天数 Int check_
time
int not null --扣薪天数 Int ) ----约束 al
te
r table CheckInfo add constraint FK_check_empId foreign key (check_empId) references Employee(emp_id) al
te
r table CheckInfo add constraint FK_check_checktId foreign key (check_empId) references checkt(checkt_id) --al
te
r table CheckInfo add constraint CK_check_hire check(check_hirecheck_hire) go --培训管理:Train if exists(select * from sysobjects where name='Train') drop table Train crea
te
table Train ( Train_id int primary key identity(1,1) not null, --培训编号 主键 自增 Int Train_
time
da
te
time
not null, --培训日期 Da
te
time
Train_address varchar(200) not null, --地址 Varchar(200) Train_con
te
nt
te
xt not null, --内容
te
xt Emp_id int not null, --职员编号 Int Train_
te
acher varchar(20) not null --讲师 Varchar(20) ) go --奖罚记录类型:PrizeAmerceType if exists(select * from sysobjects where name='PrizeAmerceType') drop table PrizeAmerceType crea
te
table PrizeAmerceType ( Prizet_id int primary key identity(1,1) not null, --奖罚记录类型id 主键 自增 Int Prizet_name varchar(50) not null, --奖罚记录名称 Varchar(50) Prizet_money money not null --奖罚金额 Money ) go --奖罚记录表:PrizeAmerceRecord if exists(select * from sysobjects where name='PrizeAmerceRecord') drop table PrizeAmerceRecord crea
te
table PrizeAmerceRecord ( Prize_id int primary key identity(1,1) not null, --奖罚记录id 主键 自增 Int Emp_id int not null, --员工id 外键 Int Prize_
time
da
te
time
not null, --时间 Da
te
time
Prizet_id int not null, --引用奖罚类型id 外键 Int Prize_desc
te
xt null, --描述 空,默认没有描述
te
xt ) ----约束 --al
te
r table PrizeAmerceRecord add constraint FK_prize_empid foreign key(prize_empId) references Employee(emp_id) --al
te
r table PrizeAmerceRecord add constraint FK_prize_prizetid foreign key(prize_prizetId) references PrizeAmerceType(prizet_id) al
te
r table PrizeAmerceRecord add constraint DF_prize_desc default('没有描述') for prize_desc go --档案:Record if exists(select * from sysobjects where name='Record') drop table Record crea
te
table Record ( Re_id int primary key identity(1,1) not null, --档案id 主键 自增 Int Re_code varchar(50) not null, --档案代码 日期+随即数生成 Varchar(50) Emp_id int not null, --员工id 外键 Int Prize_id int not null --奖罚记录id 外键 Int ) ----约束 --al
te
r table Record add constraint FK_re_empId foreign key (re_empId) references Employee(emp_id) go --薪资表:SalaryInfo if exists(select * from sysobjects where name='SalaryInfo') drop table SalaryInfo crea
te
table SalaryInfo ( Sal_id int primary key identity(1,1) not null, --薪水表ID 主键 自增 Int Emp_id int not null, --职员ID 外键 Int Sal_bonus money not null, --奖金 Money Sal_deduct numeric(18,2) not null, --扣除 Numerica(18,2) Sal_tax money not null, --扣税 Money 默认为0 Sal_sum money not null, --总薪水 Money Sal_da
te
smal
lda
te
time
not null --发放日期
smal
lda
te
time
) ----约束 --al
te
r table SalaryInfo add constraint FK_sal_empid foreign key (sal_empId) references Employee(emp_id) go --***********采购管理 --供应商级别:LevelInfo if exists(select * from sysobjects where name='LevelInfo') drop table LevelInfo crea
te
table LevelInfo ( Level_id int primary key identity(1,1) not null, --级别编号 主 自增 Int Level_name varchar(10) not null --级别名称 Varchar(10) ) go --供应商:Victualer if exists(select * from sysobjects where name='Victualer') drop table Victualer crea
te
table Victualer ( Victu_id int primary key identity(1,1) not null, --供应商编号 主 自增 Int Victu_name varchar(100) not null, --名称 Varchar(100) Level_id int not null, --级别编号 外,LevelInfo表 Int Victu_people varchar(20) not null, --联系人 Varchar(20) Victu_
te
lephone varchar(11) not null, --联系电话 Varvhar(11),必须是11位 Victu_email varchar(50) null, --邮件 空,必须符合邮件格式 Varchar(50) Victu_address
te
xt not null, --联系地址
Te
xt 默认地址不详 Victu_remark
te
xt null --备注 空,默认没有备注
Te
xt ) ----约束 --al
te
r table Victualer add constraint FK_Victu_levelId foreign key(Victu_levelId) references LevelInfo(Level_id) al
te
r table Victualer add constraint CK_Victu_
te
lephone check(len(victu_
te
lephone)=11) al
te
r table Victualer add constraint CK_Victu_email check(victu_email like '%@%.%') al
te
r table Victualer add constraint DF_Victu_remark default ('没有描述') for victu_remark al
te
r table Victualer add constraint DF_Victu_address default ('地址不详') for victu_address go --商品类别:Sort if exists(select * from sysobjects where name='Sort') drop table Sort crea
te
table Sort ( Sort_id int primary key identity(1,1) not null, --类别编号 主 自增 Int Sort_name varchar(50) not null --类别名称 Varchar(50) ) go --商品规格表:Spec if exists(select * from sysobjects where name='Spec') drop table Spec crea
te
table Spec ( Spec_id int primary key identity(1,1) not null, --规格编号 主 自增 Int Spec_name varchar(50) not null --规格名称 Varchar(50) ) go --商品表:Product if exists(select * from sysobjects where name='Product') drop table Product crea
te
table Product ( Pro_id int primary key identity(1,1) not null, --商品编号 主 自增 Int Pro_code varchar(20) not null, --商品代码 按日期+随机数生成,唯一 Varchar(20) Pro_name varchar(50) not null, --商品名称 Varchar(50) Sort_id int not null, --类别编号 外,Sort表 Int Spec_id int not null, --规格编号 外,Spec表 Int Pro_count int not null, --数量 Int Pro_inPrice money not null, --进货价 Money Pro_outPrice money not null, --销售价 Money Victu_id int not null, --供应商编号 外,Victualer表 Int 级联删除 Pro_remark
te
xt null --备注 空,默认没有备注
Te
xt ) ----约束 go --询价单:AskPrice if exists(select * from sysobjects where name='AskPrice') drop table AskPrice crea
te
table AskPrice ( Ask_id int primary key identity(1,1) not null, --询价单编号 主 自增 Int Victu_id int not null, --供应商编号 外,Victualer表 Int Pro_id int not null, --商品编号 外,Product表 Int ask_price money not null, --报价 Money Ask_
time
da
te
time
not null --添加时间 Da
te
time
) ----约束 go --采购单: BuyBill if exists(select * from sysobjects where name='BuyBill') drop table BuyBill crea
te
table BuyBill ( Buybill_id int primary key identity(1,1) not null, --采购单编号 主 自增 Int Buybill_num varchar(20) not null, --采购单据号 按日期+随机数生成,唯一 varchar(20) Emp_id int not null, --采购员编号 外,职员表 Int Buybill_
time
da
te
time
not null, --采购时间 采购时间必须在交货时间之前 Da
te
time
Buybill_deli
time
da
te
time
not null, --交货时间 Da
te
time
Buybill_remark
te
xt not null, --合同备注
Te
xt Buybill_Isexam bit not null --库管是否审批 bit ) ----约束 go --采购明细表: BuyList if exists(select * from sysobjects where name='BuyList') drop table BuyList crea
te
table BuyList ( Buylist_id int primary key identity(1,1) not null, --采购明细编号 主 自增 Int Buybill_id int not null, --采购单编号 外,Buybill表 Int Pro_id int not null, --商品编号 外,Prduct表 Int Buylist_Count int not null, --采购数量 Int Buylist_price money not null, --采购价 Money Victu_id int not null, --供应商编号 外,Vitcualer表 Int Dsub_id int not null --采购单商品仓库编号 外,DepotSubarea表 Int ) ----约束 go --采购付款单:PayBill if exists(select * from sysobjects where name='PayBill') drop table PayBill crea
te
table PayBill ( Pay_id int primary key identity(1,1) not null, --付款单编号 主 自增 Int Buybill_id int not null, --采购单编号 外,Buybill表 Int Pay_oncoming money not null, --此次付款 如果应付款分为几次付 Money Pay_deal money not null, --应付款 则应付款应该要保持一致 Money Emp_id int not null, --财务部审批人编号 外,职员表 Int Pay_Isexam bit not null, --财务部是否审批 bit Pay_remark
te
xt null --备注 空,默认没有备注
te
xt ) ----约束 go --采购退货单:MoveBill if exists(select * from sysobjects where name='MoveBill') drop table MoveBill crea
te
table MoveBill ( Move_id int primary key identity(1,1) not null, --退货单编号 主 自增 Int Buybill_id int not null, --采购单编号 外,Buybill表 Int Move_
time
da
te
time
not null, --退单日期 退单日期必须是在采购日期之后 Da
te
time
Dsub_id int not null, --库管审批人编号 外, Int Move_Isexam bit not null, --库管是否审批 Bit Move_remark
te
xt null --备注 空,默认没有备注
Te
xt ) ----约束 go --***********仓库管理 --库区表:DepotSubarea if exists(select * from sysobjects where name='DepotSubarea') drop table DepotSubarea crea
te
table DepotSubarea ( Dsub_id int primary key identity(1,1) not null, --库区id 主键 自增 Int Dsub_name varchar(10) not null,--库区名称 Varchar(10) Dsub_type varchar(10) not null--仓库类别 Varchar(10) ) go --移动类型表:Transfer if exists(select * from sysobjects where name='Transfer') drop table Transfer crea
te
table Transfer ( Tran_id int primary key identity(1,1) not null, --移动类型id 主键 自增 Int Tran_name varchar(20) not null --移动类型名称 Varchar(20) ) go --入库明细表:PutInfo if exists(select * from sysobjects where name='PutInfo') drop table PutInfo crea
te
table PutInfo ( Put_id Int primary key identity(1,1) not null, --入库明细id 主键 自增 Put_code Varchar(20) not null, --入库单代码 日期+随即数生成 Buybill_id Int not null, --采购单编号 外键 Put_
time
Da
te
time
not null, --入库时间 Put_people varchar(20) not null, --入库人 Dsub_id Int not null, --库区 外键 级联删除 Tran_id Int not null --移动类型 外键 ) ----约束 go --库存表:Stock if exists(select * from sysobjects where name='Stock') drop table Stock crea
te
table Stock ( Stock_id Int primary key identity(1,1) not null, --库存编号 主键 自增 Dsub_id Int not null, --库区id 外键 Pro_id Int not null, --商品id 外键 Stock_number Int not null --商品数量 ) ----约束 go --出库明细表:OutInfo if exists(select * from sysobjects where name='OutInfo') drop table OutInfo crea
te
table OutInfo ( Out_id Int primary key identity(1,1) not null, --出库明细id 主键 自增 Out_code Varchar(20) not null, --出库单据号 唯一 Out_
time
Da
te
time
not null, --出库时间 Out_llr Varchar(20) not null, --领料人 Out_flr Varchar(20) not null, --发料人 Out_tranId Int not null, --移动类型 Out_dsubId Int not null --库区 ) ----约束 go --补仓管理:RepairDepot if exists(select * from sysobjects where name='RepairDepot') drop table RepairDepot crea
te
table RepairDepot ( Repa_id Int primary key identity(1,1) not null, --补仓id 主键 自增 Pro_id Int not null, --商品id 外键 Repa_number Int not null, --补仓数量 Repa_dsubId Int not null, --库区表 外键 Repa_remark
te
xt null --备注 空,默认没有备注 ) ----约束 go --***********销售管理 --客户级别表(CustLevel) if exists(select * from sysobjects where name='CustLevel') drop table CustLevel crea
te
table CustLevel ( Cl_id Int primary key identity(1,1) not null, --编号 主,自增 Cl_name Varchar(10) not null, --级别名称 Cl_discount float not null --折扣 ) --约束 go --客户信息表(customer) if exists(select * from sysobjects where name='customer') drop table customer crea
te
table customer ( C_id int primary key identity(1,1) not null, --编号 主,自动增长 C_number Varchar(10) not null, --客户代号 C_name Varchar(20) not null, --客户名称 C_linkman Varchar(20) not null, --联系人 C_phone Varchar(11) not null, --联系电话 C_address
Te
xt null, --公司地址 空,默认地址不详 Cl_id Int not null, --级别编号 外 C_remark
te
xt null, --备注信息 默认没有备注 空 ) --约束 go --订单表(orders) if exists(select * from sysobjects where name='orders') drop table orders crea
te
table orders ( O_id int primary key identity(1,1) not null, --编号 主,自增 O_number Varchar(20) not null, --订单代码 日期+随即数生成 O_
time
start da
te
time
not null, --下单日期 下单时间必须在交货时间之前 O_
time
stop Da
te
time
not null, --交货日期 O_money Money not null, --下单金额 C_id Int not null, --客户编号 外 级联删除 Emp_id int not null --员工编号 外 ) --约束 go --订单明细表(OrderDetails) if exists(select * from sysobjects where name='OrderDetails') drop table OrderDetails crea
te
table OrderDetails ( Od_id Int primary key identity(1,1) not null, --编号 主,自增 O_id int not null, --订单编号 外 Pro_id int not null, --商品编号 外 Od_price Money not null, --单件金额 Od_accounts Int not null --单件数量 ) --约束 go --销售单表(Sells) if exists(select * from sysobjects where name='Sells') drop table Sells crea
te
table Sells ( Sell_id int primary key identity(1,1) not null, --编号 主,自增 O_id int not null, --订单编号 外 Sell_
time
start da
te
time
not null, --销售日期 下单时间必须在交货时间之前 Sell_
time
stop Da
te
time
not null, --交货日期 Sell_money Money not null, --销售金额 C_id Int not null, --客户编号 外 Emp_id int not null, --员工编号 外 Sell_remark
te
xt null --备注 空 ) --约束 go --销售单明细表(SellDetails) if exists(select * from sysobjects where name='SellDetails') drop table SellDetails crea
te
table SellDetails ( Selld_id int primary key identity(1,1) not null, --编号 主,自增 O_id int not null, --订单编号 Pro_id int not null, --商品编号 Selld_price Money not null, --单件金额 Selld_accounts Int not null --单件数量 ) --约束 go --***********财务管理 --财务科目表:FinaSub if exists(select * from sysobjects where name='FinaSub') drop table FinaSub crea
te
table FinaSub ( Fina_id Int primary key identity(1,1) not null, --科目编号 主,自增 Fina_name Varchar(50) not null, --科目名称 Fina_accounts Varchar(50) not null, --银行账号 随机数生成 Fina_people Varchar(50) not null, --联系人 Fina_
te
lephone Varchar(11) not null, --联系电话 Fina_mode Varchar(10) not null, --是借或贷 Fina_play Varchar(10) not null, --借贷方式(现金、发票) Fian_money money not null --金额 ) go --发票信息表:Invoice if exists(select * from sysobjects where name='Invoice') drop table Invoice crea
te
table Invoice ( Invo_id Int primary key identity(1,1) not null, --发票编号 主,自增 Invo_code Varchar(50) not null, --发票单据号 日期+随机数生成,唯一 Invo_type Varchar(10) not null, --发票类型 Invo_money money not null, --金额 Invo_use Varchar(50) not null, --发票用途 Invo_da
te
time
Da
te
time
not null, --发票日期 Emp_id int not null --财务员编号 外,职员表 ) ----约束 go --固定资产表:FixedAssets if exists(select * from sysobjects where name='FixedAssets') drop table FixedAssets crea
te
table FixedAssets ( Fix_id Int primary key identity(1,1) not null, --资产编号 主,自增 Fix_name Varchar(100) not null, --资产名称 Fix_money Money not null, --可汇兑金额 Fix_da
te
time
Da
te
time
not null, --添加时间 Fix_remark
Te
xt null, --备注 空,默认没有备注 ) ----约束 go --财务员统计视图 --***********权限管理 --用户表:UserInfo if exists(select * from sysobjects where name='UserInfo') drop table UserInfo crea
te
table UserInfo ( u_id int primary key identity(1,1) not null, --用户编号,主,自增 u_name varchar(20) not null, --用户名,即登录名 u_pass varchar(10) not null, --登录密码 u_
time
da
te
time
not null --登录时间 ) --insert into UserInfo values('admin','admin','2008-08-05') --insert into UserInfo values('yqh','yqh','2008-08-05') --insert into UserInfo values('gogo','gogo','2008-08-05') --insert into UserInfo values('wangwang','wangwang','2008-08-05') select * from UserInfo go --角色表:RolesInfo if exists(select * from sysobjects where name='RolesInfo') drop table RolesInfo crea
te
table RolesInfo ( r_id int primary key identity(1,1) not null, --角色编号,主,自增 r_name varchar(20) not null, --角色名称,即职位名称,唯一 r_desc
te
xt null --角色描述,空,默认没有描述 ) al
te
r table RolesInfo add constraint UQ_r_name unique (r_name) al
te
r table RolesInfo add constraint DF_r_desc default ('没有描述') for r_desc --insert into RolesInfo values('系统管理员','可以有任何操作') --insert into RolesInfo values('总经理','最高管理者') --insert into RolesInfo values('部门经理','管理者') --insert into RolesInfo values('普通员工',default) select * from RolesInfo go --用户和角色中间表(因为是、一对多的关系):UserRolesCen
te
r if exists(select * from sysobjects where name='UserRolesCen
te
r') drop table UserRolesCen
te
r crea
te
table UserRolesCen
te
r ( c_id int primary key identity(1,1) not null, --中间表编号,主,自增 u_id int not null, --外,用户编号,修改和删除规则都是层叠 r_id int not null --外,角色编号,修改和删除规则都是层叠 ) al
te
r table UserRolesCen
te
r add constraint FK_u_id foreign key (u_id) references UserInfo(u_id) al
te
r table UserRolesCen
te
r add constraint FK_r_id foreign key (r_id) references RolesInfo(r_id) --insert into UserRolesCen
te
r values(1,1) --insert into UserRolesCen
te
r values(1,2) --insert into UserRolesCen
te
r values(2,2) --insert into UserRolesCen
te
r values(3,3) --insert into UserRolesCen
te
r values(4,4) select * from UserRolesCen
te
r --dele
te
from UserRolesCen
te
r where c_id=5 --查询视图 select * from UserRolesView --查询角色1中已有的用户,利用视图 select * from UserRolesView where r_id=1 --查询角色1中没有的用户,利用子查询,用户表中的所有用户减去角色中已有的用户 Select * from UserInfo where u_id not in (select u_id from UserRolesView where r_id=1) go --菜单表:MenuInfo if exists(select * from sysobjects where name='MenuInfo') drop table MenuInfo crea
te
table MenuInfo ( M_id Int primary key identity(1,1) not null,--菜单编号 主,自增 M_name Varchar(50) not null,--菜单名称 M_url Varchar(50) null,--菜单链接 空 M_parentId int not null,--父菜单编号 ) --约束 --insert into MenuInfo values('系统权限管理','',0) --insert into MenuInfo values('人力资源管理','',0) --insert into MenuInfo values('采购管理','',0) --insert into MenuInfo values('仓库管理','',0) --insert into MenuInfo values('销售管理','',0) --insert into MenuInfo values('财务管理','',0) select * from MenuInfo go --4.角色和菜单中间表即权限表:PowerInfo if exists(select * from sysobjects where name='PowerInfo') drop table PowerInfo crea
te
table PowerInfo ( P_id Int primary key identity(1,1) not null,--权限编号 主 R_id Int not null,--角色编号 外 ,修改和删除规则都是层叠 M_id int not null,--菜单编号 外 ,修改和删除规则都是层叠 ) --约束 al
te
r table PowerInfo add constraint FK_pr_id foreign key (r_id) references RolesInfo(r_id) al
te
r table PowerInfo add constraint FK_m_id foreign key (m_id) references MenuInfo(m_id) --insert into PowerInfo values(1,1) --insert into PowerInfo values(1,2) --insert into PowerInfo values(2,2) --insert into PowerInfo values(3,3) --insert into PowerInfo values(4,4) select * from PowerInfo --查询视图 select * from RolesMenuView --查询角色1中已有的功能,利用视图 select * from RolesMenuView where r_id=1 --查询角色1中没有的功能,利用子查询,菜单表中的所有功能减去角色中已有的功能 Select * from MenuInfo where m_id not in (select m_id from RolesMenuView where r_id=1) go
da
te
time
和
smal
lda
te
time
da
te
time
和
smal
lda
te
time
用于表示某天的日期和时间的数据类型。 da
te
time
和
smal
lda
te
time
表示某天的日期和时间。 数据类型 范围 精确度 da
te
time
1753 年 1 月 1 日到 9999 年 12 月 31 日 3.33 毫秒
smal
ld...
SqlServer中Da
te
time
和
Smal
lDa
te
Time
如何选择?
da
te
time
占8字节,精度3.33毫秒,时间从1753.1.1到9999.12.31
smal
lda
te
time
占4字节,精度1分钟,时间从1900.1.1到2079.6.6 如果需要用到“秒”,毫无疑问选择da
te
time
!
da
te
time
与
smal
lda
te
time
之间的
区别
1、一直以为
smal
lda
te
time
和da
te
time
的差别只是在于时间范围:
smal
lda
te
time
的有效时间范围1900/1/1~2079/6/6 da
te
time
的有效时间范围1753/1/1~9999/12/31 所以我判断如果该值不用到太远的日期范围,就会使用
smal
lda
te
time
。 2、但我忽略了更关键的差别,那就是
smal
lda
te
time
只精准到分,而da
te
t
MS-SQL Server
34,588
社区成员
254,588
社区内容
发帖
与我相关
我的任务
MS-SQL Server
MS-SQL Server相关内容讨论专区
复制链接
扫一扫
分享
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章