码迷,mamicode.com
首页 > 其他好文 > 详细

Different between datetime and timestamp, and its setting

时间:2017-01-27 11:50:23      阅读:212      评论:0      收藏:0      [点我收藏+]

标签:ansi   can   copy   nbsp   sqlsever   ignore   padding   pen   diff   

According to the documentationtimestamp is a synonym for rowversion - it‘s automatically generated and guaranteed1 to be unique. datetime isn‘t - it‘s just a data type which handles dates and times, and can be client-specified on insert etc.

Here is an example to use both datetime and timestamp in SQLSever . problem will happen, when you try to copy a datebase

to a new database, then dates about the timestamp is not to copy........So what should we do about it. 

USE [SWSK_YOSAN_161115]
GO

/****** Object:  Table [dbo].[T_TEST]    Script Date: 2017/01/27 11:55:09 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[T_TEST](
    [JIGYOCD] [char](2) NOT NULL,
    [ORDERNO] [char](8) NOT NULL,
    [LASTUPDATEYMD] [datetime] NULL CONSTRAINT [DF_T_TEST_LASTUPDATEYMD]  DEFAULT (getdate()),
    [LASTUPDATEID] [varchar](20) NULL,
    [LASTUPDPGID] [varchar](20) NULL,
    [VERSIONNO] [timestamp] NULL,
 CONSTRAINT [PK_T_TEST] PRIMARY KEY CLUSTERED 
(
    [JIGYOCD] ASC,
    [ORDERNO] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO
SELECT [JIGYOCD]
,[ORDERNO]
,[LASTUPDATEYMD]
,[LASTUPDATEID]
,[LASTUPDPGID]
,[VERSIONNO]
FROM [dbo].[T_TEST]
GO

  

 

 

Different between datetime and timestamp, and its setting

标签:ansi   can   copy   nbsp   sqlsever   ignore   padding   pen   diff   

原文地址:http://www.cnblogs.com/tomclock/p/6353699.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!