Niranjan Godbole
Niranjan Godbole

Reputation: 2175

Timestamp column not saving data in sql table

Hi I am designing table called user-registration with few fields. I have created date and updated date and requirement is to put time stamp for created and updated fields. I googled and found only one time stamp we can have per table and value will be inserted automatically and no need to supply value to it. Please correct me if i am wrong. Currently when i insert row of data to table i am getting in time stamp field. Below is my table structure.

CREATE TABLE [dbo].[NCT_UserRegistration](
    [User_Id] [int] IDENTITY(1,1) NOT NULL,
    [User_EmailId] [varchar](255) NULL,
    [User_Password] [varchar](512) NULL,
    [User_Name] [varchar](255) NULL,
    [User_MobileNum] [varchar](20) NULL,
    [User_Status] [varchar](15) NULL CONSTRAINT chk_Status CHECK ([User_Status] IN ('ENABLED', 'DISABLED')),
    [User_Role] [varchar](20) NULL CONSTRAINT chk_Role CHECK ([User_Role] IN ('SUPER_ADMIN','PROJECT_ADMIN')),
    [User_CreatedDate] [timestamp] NULL,
    [User_UpdatedDate] [datetime] NULL,
    [Name] [varchar](30) NULL
)

I tried as below.

ALTER TABLE [NCT_UserRegistration]
ALTER COLUMN  [User_CreatedDate] TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

and ended up with Incorrect syntax near the keyword 'DEFAULT'.

Any help would be appreciated. Thank you.

Upvotes: 0

Views: 447

Answers (1)

Sonali
Sonali

Reputation: 67

Try this in Table structure :-

User_CreatedDate TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP

Upvotes: 1

Related Questions