Quantcast
Channel: SQLServerCentral » SQL Server 2008 » SQL Server 2008 Administration » Latest topics
Viewing all articles
Browse latest Browse all 3118

Ask for help in index

$
0
0
Hi,I'm a beginner in index. I've table and data as following,[code="sql"]CREATE TABLE [dbo].[Zip]( [City_Cd] [varchar](100) NULL, [Zip_Cd] [varchar](10) NULL) ON [PRIMARY]GOSET ANSI_PADDING OFFGOINSERT [dbo].[Zip] ([City_Cd], [Zip_Cd]) VALUES (N'Mobile', N'36601')INSERT [dbo].[Zip] ([City_Cd], [Zip_Cd]) VALUES (N'New Orleans', N'70121')INSERT [dbo].[Zip] ([City_Cd], [Zip_Cd]) VALUES (N'Luling', N'70070')/****** Object: Table [dbo].[State] Script Date: 12/26/2012 19:01:30 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[State]( [State_Cd] [char](2) NULL, [Descr] [varchar](150) NULL) ON [PRIMARY]GOSET ANSI_PADDING OFFGOINSERT [dbo].[State] ([State_Cd], [Descr]) VALUES (N'AL', N'Alabama')INSERT [dbo].[State] ([State_Cd], [Descr]) VALUES (N'LA', N'Louisiana')/****** Object: Table [dbo].[City] Script Date: 12/26/2012 19:01:30 ******/SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOSET ANSI_PADDING ONGOCREATE TABLE [dbo].[City]( [State_Cd] [char](2) NULL, [City_Cd] [varchar](100) NULL) ON [PRIMARY]GOSET ANSI_PADDING OFFGOINSERT [dbo].[City] ([State_Cd], [City_Cd]) VALUES (N'AL', N'Mobile')INSERT [dbo].[City] ([State_Cd], [City_Cd]) VALUES (N'LA', N'New Orleans')INSERT [dbo].[City] ([State_Cd], [City_Cd]) VALUES (N'LA', N'Luling')[/code]Then, I execute SQL as following[code="sql"]SELECT s.[Descr],c.City_CdFROM dbo.[State] sINNER JOIN dbo.[City] c ON s.[State_Cd] = c.[State_Cd][/code]The Execution Plan as following,[img]http://i.imgur.com/dsDC4.png[/img]Then, I create an index as following[code="sql"]CREATE NONCLUSTERED INDEX [IX_State_State_Cd_001] ON [dbo].[State] ( [State_Cd] ASC)INCLUDE ( [Descr]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]CREATE NONCLUSTERED INDEX [IX_City_State_Cd_001] ON [dbo].[City] ( [State_Cd] ASC)INCLUDE ( [City_Cd]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY][/code]Then, my Execution Plan as following[img]http://i.imgur.com/sU1Vh.png[/img]How do I want to make both of them (State and City) is Index Seek?If it can, please guide meReally looking for help

Viewing all articles
Browse latest Browse all 3118

Trending Articles