Quantcast
Channel: Teguh Triharto Learning Center
Viewing all articles
Browse latest Browse all 413

.::: Insert data table to another table with different Database in SQL Server :::.

$
0
0
 

  A. Without Date

1. Check

select * from teguhth..pembelian
 


2. create table & insert firstime

-- pertama kali insert table
select * into dwh..pembelian_clone from teguhth..pembelian

 3. insert data after create table
-- insert data after create table
insert into dwh..pembelian_clone select * from teguhth..pembelian;


4. check

select * from teguhth..pembelian
select * from dwh..pembelian_clone;
 


5. table after create
USE [dwh]
GO

CREATE TABLE [dbo].[pembelian_clone](
    [KODE_PEMBELIAN] [char](10) NOT NULL,
    [KODE_BARANG] [char](6) NOT NULL,
    [KODE_CUSTOMER] [char](6) NOT NULL,
    [TANGGAL_PEMBELIAN] [date] NULL,
    [JUMLAH_PEMBELIAN] [decimal](4, 0) NULL
) ON [PRIMARY]
GO


B. with Date

1. Check

select *,GETDATE() AS [Date Cron] from teguhth..pembelian;

select *,CAST(GETDATE() AS date) AS [Date Cron]
from teguhth..pembelian
 

2. create table & insert firstime

-- pertama kali insert table
select *,GETDATE() AS [Date Cron] into dwh..pembelian_clone from teguhth..pembelian


3. insert data after create table
-- insert data after create table
insert into dwh..pembelian_clone select *, GETDATE() AS [Date Cron] from teguhth..pembelian;


4. check
select *,GETDATE() AS [Date Cron] from teguhth..pembelian
select * from dwh..pembelian_clone;
 


5. table after create

USE [dwh]
GO

CREATE TABLE [dbo].[pembelian_clone](
    [KODE_PEMBELIAN] [char](10) NOT NULL,
    [KODE_BARANG] [char](6) NOT NULL,
    [KODE_CUSTOMER] [char](6) NOT NULL,
    [TANGGAL_PEMBELIAN] [date] NULL,
    [JUMLAH_PEMBELIAN] [decimal](4, 0) NULL,
    [Date Cron] [datetime] NOT NULL
) ON [PRIMARY]
GO

Viewing all articles
Browse latest Browse all 413

Trending Articles