Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (6.1k points)

I have been trying to insert a date when a user decides to deactivate or activate an UserID. I am trying to use an SP to trigger that but apparently, this is harder than I thought it would be.

I can do a

SELECT GETDATE()

to get the date but is there any way to insert that information from GETDATE and put it into a column I want?

1 Answer

0 votes
by (12.7k points)

To insert a new row into the given table (tblTable) :

INSERT INTO tblTable (DateColumn) VALUES (GETDATE())

To update an existing row :

UPDATE tblTable SET DateColumn = GETDATE()
 WHERE ID = RequiredUpdateID

Note that when Inserting a new row you have to observe any constraints which are on the table - most probably the NOT NULL constraint - so you may need to provide values for the other columns eg...

INSERT INTO tblTable (Name, Type, DateColumn) VALUES ('John', 7, GETDATE())

Want to be a SQL expert? Come and join this SQL Certification by Intellipaat.

Do check out the video below

Related questions

Browse Categories

...