Adding date/time column to audit table

JRockFL
JRockFL used Ask the Experts™
on
I just added a column called AuditDate with a default value of GetDate()
and now I get this message.

Column name or number of supplied values does not match table definition.

ALTER TRIGGER [dbo].[OrdersInsertUpdate]
ON [dbo].[Orders]
AFTER INSERT, UPDATE
AS
BEGIN
      SET NOCOUNT ON;
      INSERT INTO OrdersAudit SELECT * FROM INSERTED
END

How can I correct this?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Select * is more than likely returning a different number of columns that your OrdersAudit table expects. Change * with explicit list of the columns you want to put in the audit table.
Scott PletcherSenior DBA
Most Valuable Expert 2018
Top Expert 2014
Commented:
If you added AuditDate as the last column, you can do this:


      INSERT INTO OrdersAudit SELECT *, GETDATE() FROM INSERTED

Author

Commented:
Thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial