What the title says, I want to insert data from a database to another database. The first database "DB1" is the source and the second database "DB2" is the target.
The relevant tables are defined as follows:
DB1 => tbl_Target
==================================
Id | Date | Name | Age | Num_Aucts
==================================
DB2 => tbl_Source
======================
Name | Age | Num_Aucts
======================
Well, tbl_Source contains 40 rows of data. I need to transfer these rows into tbl_Target. But how you can see tbl_Target has two additional columns Idand Date. Id will set automatically. The important column is Date. In this column I want to set the currently date. In this case from today. How can I define this in a trigger frunction in SQL Server with T-SQL?
I have begun in this direction:
USE DB1
GO
CREATE TRIGGER trg_Insert_tblSource ON tbl_Source
FOR INSERT AS
BEGIN
INSERT INTO DB2.dbo.tbl_Target ([Date], [Name], [Age], [Num_Aucts])
SELECT ??? // How to get the current date?
Can anyone help me? Do I need a stored procedure?