hi i have two table which i join them i couldnt get data even when i wanna get even one row .
here is my code :
select top 1 *from kalite_kontrol k inner join is_acma_bar b on k.is_num=b.is_num and k.oper_num=b.oper_num where b.pers_num=272 and k.tarih='2016-03-23'
i couldnt get data by query . i think i need to make index but i tried all possibility thant i know.
for any support i ll be appreciate, please help me.
and my tables details:
CREATE TABLE [dbo].[is_acma_bar] (
[is_num] [bigint] NOT NULL ,
[barkod] [varchar] (10) COLLATE Turkish_CI_AS NOT NULL ,
[pers_num] [bigint] NULL ,
[oper_num] [int] NOT NULL ,
[oper_var] [smallint] NOT NULL ,
[tarih] [smalldatetime] NULL ,
[saat] [datetime] NULL ,
[adet] [int] NOT NULL ,
[bil_no] [tinyint] NULL ,
[drv_num] [tinyint] NULL ,
[trm_num] [smallint] NULL ,
[bit_tarih] [smalldatetime] NULL ,
[bit_saat] [datetime] NULL ,
[test_deger] [float] NULL ,
[test_deger2] [float] NULL ,
[test_deger3] [float] NULL ,
[inoutno] [bigint] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[kalite_kontrol] (
[is_num] [bigint] NOT NULL ,
[oper_num] [int] NOT NULL ,
[oper_var] [smallint] NOT NULL ,
[hata] [tinyint] NULL ,
[saat] [datetime] NOT NULL ,
[tarih] [smalldatetime] NOT NULL ,
[kp_num] [bigint] NOT NULL ,
[kont_adet] [tinyint] NULL ,
[s_no] [bigint] IDENTITY (1, 1) NOT NULL ,
[kalite_tp] [tinyint] NOT NULL ,
[merr_code] [varchar] (10) COLLATE Turkish_CI_AS NOT NULL ,
[serr_code] [varchar] (10) COLLATE Turkish_CI_AS NOT NULL ,
[area_code] [varchar] (10) COLLATE Turkish_CI_AS NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[is_acma_bar] WITH NOCHECK ADD
CONSTRAINT [PK_is_bar] PRIMARY KEY CLUSTERED
(
[is_num],
[oper_num],
[oper_var]
) WITH FILLFACTOR = 50 ON [PRIMARY]
GO
ALTER TABLE [dbo].[kalite_kontrol] WITH NOCHECK ADD
CONSTRAINT [PK_kalite_kontrol] PRIMARY KEY CLUSTERED
(
[is_num],
[oper_num],
[oper_var],
[saat],
[tarih],
[kalite_tp],
[merr_code],
[serr_code]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [is_bar_tar] ON [dbo].[is_acma_bar]([tarih]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [is_bar_pers] ON [dbo].[is_acma_bar]([pers_num]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE UNIQUE INDEX [is_bar_bar] ON [dbo].[is_acma_bar]([barkod]) WITH IGNORE_DUP_KEY ON [PRIMARY]
GO
CREATE INDEX [is_bar_isnum] ON [dbo].[is_acma_bar]([is_num]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [is_bar_perstar] ON [dbo].[is_acma_bar]([pers_num], [tarih]) ON [PRIMARY]
GO
CREATE INDEX [IX_is_acma_bar_inoutno] ON [dbo].[is_acma_bar]([inoutno]) ON [PRIMARY]
GO
CREATE INDEX [IX_is_bar_oper] ON [dbo].[is_acma_bar]([oper_num]) ON [PRIMARY]
GO
CREATE INDEX [kalite_kont_ind] ON [dbo].[kalite_kontrol]([s_no]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [IX_kk_is_oper_var] ON [dbo].[kalite_kontrol]([is_num], [oper_num], [oper_var]) ON [PRIMARY]
GO
CREATE INDEX [IX_kk_is_tp] ON [dbo].[kalite_kontrol]([is_num], [kalite_tp]) ON [PRIMARY]
GO
CREATE INDEX [IX_kk_tar_tp_kpnum] ON [dbo].[kalite_kontrol]([tarih], [kalite_tp], [kp_num]) ON [PRIMARY]
GO
CREATE INDEX [IX_kk_tar] ON [dbo].[kalite_kontrol]([tarih]) ON [PRIMARY]
GO
CREATE INDEX [IX_kk_kal_tp] ON [dbo].[kalite_kontrol]([kalite_tp]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[kalite_kontrol] ADD
CONSTRAINT [FK_kalite_kontrol_ab_kk_err_area] FOREIGN KEY
(
[area_code]
) REFERENCES [dbo].[ab_kk_err_area] (
[area_code]
),
CONSTRAINT [FK_kalite_kontrol_ab_kk_err_type] FOREIGN KEY
(
[merr_code],
[serr_code],
[area_code]
) REFERENCES [dbo].[ab_kk_err_type] (
[merr_code],
[serr_code],
[area_code]
),
CONSTRAINT [FK_kalite_kontrol_ab_kk_main_err] FOREIGN KEY
(
[merr_code]
) REFERENCES [dbo].[ab_kk_main_err] (
[merr_code]
),
CONSTRAINT [FK_kalite_kontrol_ab_kk_sub_err] FOREIGN KEY
(
[merr_code],
[serr_code]
) REFERENCES [dbo].[ab_kk_sub_err] (
[merr_code],
[serr_code]
)
GO
here is my code :
select top 1 *from kalite_kontrol k inner join is_acma_bar b on k.is_num=b.is_num and k.oper_num=b.oper_num where b.pers_num=272 and k.tarih='2016-03-23'
i couldnt get data by query . i think i need to make index but i tried all possibility thant i know.
for any support i ll be appreciate, please help me.
and my tables details:
CREATE TABLE [dbo].[is_acma_bar] (
[is_num] [bigint] NOT NULL ,
[barkod] [varchar] (10) COLLATE Turkish_CI_AS NOT NULL ,
[pers_num] [bigint] NULL ,
[oper_num] [int] NOT NULL ,
[oper_var] [smallint] NOT NULL ,
[tarih] [smalldatetime] NULL ,
[saat] [datetime] NULL ,
[adet] [int] NOT NULL ,
[bil_no] [tinyint] NULL ,
[drv_num] [tinyint] NULL ,
[trm_num] [smallint] NULL ,
[bit_tarih] [smalldatetime] NULL ,
[bit_saat] [datetime] NULL ,
[test_deger] [float] NULL ,
[test_deger2] [float] NULL ,
[test_deger3] [float] NULL ,
[inoutno] [bigint] NULL
) ON [PRIMARY]
GO
CREATE TABLE [dbo].[kalite_kontrol] (
[is_num] [bigint] NOT NULL ,
[oper_num] [int] NOT NULL ,
[oper_var] [smallint] NOT NULL ,
[hata] [tinyint] NULL ,
[saat] [datetime] NOT NULL ,
[tarih] [smalldatetime] NOT NULL ,
[kp_num] [bigint] NOT NULL ,
[kont_adet] [tinyint] NULL ,
[s_no] [bigint] IDENTITY (1, 1) NOT NULL ,
[kalite_tp] [tinyint] NOT NULL ,
[merr_code] [varchar] (10) COLLATE Turkish_CI_AS NOT NULL ,
[serr_code] [varchar] (10) COLLATE Turkish_CI_AS NOT NULL ,
[area_code] [varchar] (10) COLLATE Turkish_CI_AS NOT NULL
) ON [PRIMARY]
GO
ALTER TABLE [dbo].[is_acma_bar] WITH NOCHECK ADD
CONSTRAINT [PK_is_bar] PRIMARY KEY CLUSTERED
(
[is_num],
[oper_num],
[oper_var]
) WITH FILLFACTOR = 50 ON [PRIMARY]
GO
ALTER TABLE [dbo].[kalite_kontrol] WITH NOCHECK ADD
CONSTRAINT [PK_kalite_kontrol] PRIMARY KEY CLUSTERED
(
[is_num],
[oper_num],
[oper_var],
[saat],
[tarih],
[kalite_tp],
[merr_code],
[serr_code]
) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [is_bar_tar] ON [dbo].[is_acma_bar]([tarih]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [is_bar_pers] ON [dbo].[is_acma_bar]([pers_num]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE UNIQUE INDEX [is_bar_bar] ON [dbo].[is_acma_bar]([barkod]) WITH IGNORE_DUP_KEY ON [PRIMARY]
GO
CREATE INDEX [is_bar_isnum] ON [dbo].[is_acma_bar]([is_num]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [is_bar_perstar] ON [dbo].[is_acma_bar]([pers_num], [tarih]) ON [PRIMARY]
GO
CREATE INDEX [IX_is_acma_bar_inoutno] ON [dbo].[is_acma_bar]([inoutno]) ON [PRIMARY]
GO
CREATE INDEX [IX_is_bar_oper] ON [dbo].[is_acma_bar]([oper_num]) ON [PRIMARY]
GO
CREATE INDEX [kalite_kont_ind] ON [dbo].[kalite_kontrol]([s_no]) WITH FILLFACTOR = 90 ON [PRIMARY]
GO
CREATE INDEX [IX_kk_is_oper_var] ON [dbo].[kalite_kontrol]([is_num], [oper_num], [oper_var]) ON [PRIMARY]
GO
CREATE INDEX [IX_kk_is_tp] ON [dbo].[kalite_kontrol]([is_num], [kalite_tp]) ON [PRIMARY]
GO
CREATE INDEX [IX_kk_tar_tp_kpnum] ON [dbo].[kalite_kontrol]([tarih], [kalite_tp], [kp_num]) ON [PRIMARY]
GO
CREATE INDEX [IX_kk_tar] ON [dbo].[kalite_kontrol]([tarih]) ON [PRIMARY]
GO
CREATE INDEX [IX_kk_kal_tp] ON [dbo].[kalite_kontrol]([kalite_tp]) ON [PRIMARY]
GO
ALTER TABLE [dbo].[kalite_kontrol] ADD
CONSTRAINT [FK_kalite_kontrol_ab_kk_err_area] FOREIGN KEY
(
[area_code]
) REFERENCES [dbo].[ab_kk_err_area] (
[area_code]
),
CONSTRAINT [FK_kalite_kontrol_ab_kk_err_type] FOREIGN KEY
(
[merr_code],
[serr_code],
[area_code]
) REFERENCES [dbo].[ab_kk_err_type] (
[merr_code],
[serr_code],
[area_code]
),
CONSTRAINT [FK_kalite_kontrol_ab_kk_main_err] FOREIGN KEY
(
[merr_code]
) REFERENCES [dbo].[ab_kk_main_err] (
[merr_code]
),
CONSTRAINT [FK_kalite_kontrol_ab_kk_sub_err] FOREIGN KEY
(
[merr_code],
[serr_code]
) REFERENCES [dbo].[ab_kk_sub_err] (
[merr_code],
[serr_code]
)
GO