Different between datetime and timestamp, and its setting

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

  

 
Love it, and you live without it
原文地址:https://www.cnblogs.com/tomclock/p/6353699.html