A. Create Database & Table
create database teguhth
go
1. Table barang
-- table barang with index
CREATE TABLE [dbo].[barang](
[KODE_BARANG] [char](6) NOT NULL,
[NAMA_BARANG] [varchar](25) NULL,
[SATUAN_BARANG] [varchar](20) NULL,
[STOK_BARANG] [decimal](4, 0) NULL,
PRIMARY KEY CLUSTERED ([KODE_BARANG] ASC))
-- create table not using index
CREATE TABLE [dbo].[barang](
[KODE_BARANG] [char](6) NOT NULL,
[NAMA_BARANG] [varchar](25) NULL,
[SATUAN_BARANG] [varchar](20) NULL,
[STOK_BARANG] [decimal](4, 0) NULL)
-- with additional index
ALTER TABLE [dbo].[barang] ADD PRIMARY KEY CLUSTERED ([KODE_BARANG] ASC)
2. Table customer
-- table customer with index
CREATE TABLE [dbo].[customer](
[KODE_CUSTOMER] [char](6) NOT NULL,
[NAMA_CUSTOMER] [varchar](30) NULL,
[ALAMAT_CUSTOMER] [varchar](30) NULL,
[KOTA_CUSTOMER] [varchar](15) NULL,
[TELEPON_CUSTOMER] [varchar](15) NULL,
PRIMARY KEY CLUSTERED ([KODE_CUSTOMER] ASC))
-- create table not using index
CREATE TABLE [dbo].[customer](
[KODE_CUSTOMER] [char](6) NOT NULL,
[NAMA_CUSTOMER] [varchar](30) NULL,
[ALAMAT_CUSTOMER] [varchar](30) NULL,
[KOTA_CUSTOMER] [varchar](15) NULL,
[TELEPON_CUSTOMER] [varchar](15) NULL)
-- with additional index
ALTER TABLE [dbo].[customer] ADD PRIMARY KEY CLUSTERED ([KODE_CUSTOMER] ASC)
3. Table suplier
-- table suplier with index
CREATE TABLE [dbo].[suplier](
[KODE_SUPLIER] [char](5) NOT NULL,
[NAMA_SUPLIER] [varchar](30) NULL,
[ALAMAT_SUPLIER] [varchar](30) NULL,
[KOTA_SUPLIER] [varchar](15) NULL,
[TELEPON_SUPLIER] [varchar](15) NULL,
PRIMARY KEY CLUSTERED ([KODE_SUPLIER] ASC))
-- create table not using index
CREATE TABLE [dbo].[suplier](
[KODE_SUPLIER] [char](5) NOT NULL,
[NAMA_SUPLIER] [varchar](30) NULL,
[ALAMAT_SUPLIER] [varchar](30) NULL,
[KOTA_SUPLIER] [varchar](15) NULL,
[TELEPON_SUPLIER] [varchar](15) NULL)
-- with additional index
ALTER TABLE [dbo].[suplier] ADD PRIMARY KEY CLUSTERED ([KODE_SUPLIER] ASC)
4. Table pasok
-- table pasok with index
CREATE TABLE [dbo].[pasok](
[KODE_PASOK] [char](10) NOT NULL,
[KODE_BARANG] [char](6) NOT NULL,
[KODE_SUPLIER] [char](5) NOT NULL,
[TANGGAL_PASOK] [date] NULL,
[JUMLAH_PASOK] [decimal](4, 0) NULL,
PRIMARY KEY CLUSTERED ([KODE_PASOK] ASC,[KODE_BARANG] ASC,[KODE_SUPLIER] ASC))
GO
ALTER TABLE [dbo].[pasok] WITH CHECK ADD FOREIGN KEY([KODE_BARANG])
REFERENCES [dbo].[barang] ([KODE_BARANG])
GO
ALTER TABLE [dbo].[pasok] WITH CHECK ADD FOREIGN KEY([KODE_SUPLIER])
REFERENCES [dbo].[suplier] ([KODE_SUPLIER])
GO
-- create table not using index
CREATE TABLE [dbo].[pasok](
[KODE_PASOK] [char](10) NOT NULL,
[KODE_BARANG] [char](6) NOT NULL,
[KODE_SUPLIER] [char](5) NOT NULL,
[TANGGAL_PASOK] [date] NULL,
[JUMLAH_PASOK] [decimal](4, 0) NULL)
-- with additional index
ALTER TABLE [dbo].[pasok] ADD PRIMARY KEY CLUSTERED ([KODE_PASOK] ASC, [KODE_BARANG] ASC,[KODE_SUPLIER] ASC )
-- with additional foreign key
ALTER TABLE [dbo].[pasok] WITH CHECK ADD FOREIGN KEY([KODE_BARANG])
REFERENCES [dbo].[barang] ([KODE_BARANG])
GO
ALTER TABLE [dbo].[pasok] WITH CHECK ADD FOREIGN KEY([KODE_SUPLIER])
REFERENCES [dbo].[suplier] ([KODE_SUPLIER])
GO
5. Table pembelian
-- table pembelian with index
CREATE TABLE [dbo].[pembelian](
[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,
PRIMARY KEY CLUSTERED ([KODE_PEMBELIAN] ASC,[KODE_BARANG] ASC,[KODE_CUSTOMER] ASC))
ALTER TABLE [dbo].[pembelian] WITH CHECK ADD FOREIGN KEY([KODE_BARANG])
REFERENCES [dbo].[barang] ([KODE_BARANG])
GO
ALTER TABLE [dbo].[pembelian] WITH CHECK ADD FOREIGN KEY([KODE_CUSTOMER])
REFERENCES [dbo].[customer] ([KODE_CUSTOMER])
GO
-- create table not using index
CREATE TABLE [dbo].[pembelian](
[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)
-- with additional index
ALTER TABLE [dbo].[pembelian] ADD PRIMARY KEY CLUSTERED ([KODE_PEMBELIAN] ASC, [KODE_BARANG] ASC,[KODE_CUSTOMER] ASC)
-- with additional foreign key
ALTER TABLE [dbo].[pembelian] WITH CHECK ADD FOREIGN KEY([KODE_BARANG])
REFERENCES [dbo].[barang] ([KODE_BARANG])
GO
ALTER TABLE [dbo].[pembelian] WITH CHECK ADD FOREIGN KEY([KODE_CUSTOMER])
REFERENCES [dbo].[customer] ([KODE_CUSTOMER])
GO
B. Insert row table using Query SQL
C. Insert row table using Store Procedure & Function
No comments:
Post a Comment