Step 1. SQL Server Table and Stored Procedure
First we create a table called "mysitemap". Open SQL Server and open a new query window in your database. Cut and
paste the following SQL statement below to create the table. This table will store our data about the urls on our webite
that we want search engines to find.
CREATE TABLE [dbo].[MySitemap](
[ID] [int] IDENTITY(1,1) NOT NULL,
[Location] [varchar](200) NULL,
[ChangeFreq] [varchar](20) NULL CONSTRAINT [DF_MySitemap_ChangeFreq] DEFAULT ('daily'),
[Priority] [varchar](3) NULL CONSTRAINT [DF_MySitemap_Priority] DEFAULT ((0.5)),
[Category] [varchar](50) NULL,
CONSTRAINT [PK_MySitemap] PRIMARY KEY CLUSTERED
(
[ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF,
IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
|
After adding some data your table should look similar to this with different urls of course.
Next keeping an eye on security and performance we'll create a SQL Server stored procedure called sp_mysitemap_select to query the
urls from the table we just created. Be sure to assign execute permissions for this stored procedure to the sql login that
your web site uses to query the database.
We are going to add a conditional statement to this stored procedure so that we can use it later on in the example to create
navigation menus for the site as well. This way once we have a new page ready on the site all we have to do is add the url to the SQL table
and it will be available in the navigation menu as well as the site map automatically.
CREATE PROCEDURE [dbo].[sp_mysitemap_select]
(
@category varchar(50)
)
AS
if (@category is null)
begin
select Location, ChangeFreq, Priority from mysitemap
order by Category
end
else
begin
select Location from mysitemap where Category=@category
end
return
|
Being good programmers we always test our code on the database before hooking it into a web page so manually execute the store procedure we just created in a query window


Next Lesson
In Step 2. Create Dynamic Sitemap using ASP.NET we'll create our ASP.NET page to execute the stored procedure we created and then
integrate the sitemap protocol XML with our data.
|