DotNetNuke Wiki


SQL Scripts

Modified on 2012/02/06 06:26 AM by ept Categorized as Architecture

DotnetNuke SQL Scripts»

Generating SQL Scripts in DotNetNuke is an important thing to understand, below we cover some of the basics that everyone generating SQL Scripts should keep in mind.

Repeatable SQL Scripts»

When writing SQL Scripts for DNN you should write them in a manner that you can execute them over and over without them throwing errors. This is typically done by always checking for something before doing something. For example, if you are adding a table, you should always check to make sure that table doesn't exist before adding it. How you handle it if it does exist is up to you, you could drop it, or you could simply choose to not create it again. Here's some sample script that does just that from the http://dnnsimplearticle.codeplex.com project.

/** CREATE DNNSimpleArticle_Article Table **/

IF  EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'{databaseOwner}[{objectQualifier}DNNSimpleArticle_Article]') AND type in (N'U'))
DROP TABLE {databaseOwner}[{objectQualifier}DNNSimpleArticle_Article]
GO

IF NOT EXISTS (SELECT * FROM dbo.sysobjects WHERE id = object_id(N'{databaseOwner}[{objectQualifier}DNNSimpleArticle_Article]') and OBJECTPROPERTY(id, N'IsTable') = 1)
	BEGIN
		CREATE TABLE {databaseOwner}[{objectQualifier}DNNSimpleArticle_Article](
			[ID] [int] NOT NULL IDENTITY (1, 1),
			[Title] [nvarchar](max) NULL,
			[Description] [nvarchar](max) NULL,
			[Body] [nvarchar](max) NULL,
			[CreatedOnDate] [datetime] NULL,
			[LastModifiedOnDate] [datetime] NULL,
			[CreatedByUserID] [int] NULL,
			[LastModifiedByUserID] [int] NULL,
			[ModuleId] [int] NULL,
			[ContentItemId] [int] NULL

		 CONSTRAINT [PK_{objectQualifier}DNNSimpleArticle_Article] PRIMARY KEY CLUSTERED 
		(

			[ID] ASC{br}
		)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) 
		) 
	END
GO





Tokens»

There are two common tokens in DotNetNuke SQL Scripts that you should utilize when you create SQL scripts. databaseOwner and objectQualifier, these tokens will cause SQL scripts to not execute in tools such as Query Analyzer or SQL Management Studio's query window, but will run on the Host/SQL page of a DotNetNuke website. DNN replaces these tokens at execution time with the values defined in the web.config file of the website.

Versions»

Creating SQL Script versions is an important feature to understand when you are developing modules that are upgradeable, meaning someone who is using Version 1 of a module can easily upgrade to Version 2 of a module. More info coming soon

Sample Project»

The SQL script used in the example above is from the DNNSimpleArticle project on Codeplex http://dnnsimplearticle.codeplex.com
Attend A Webinar
Free Demo Site
Download DotNetNuke Professional Edition Trial
Have Someone Contact Me
Have Someone Contact Me

Like Us on Facebook Join our Network on LinkedIn Follow DNN Corporate on Twitter Follow DNN on Twitter

Advertisers

Sponsors

DotNetNuke Corporation

DotNetNuke Corp. is the steward of the DotNetNuke open source project, the most widely adopted Web Content Management Platform for building web sites and web applications on Microsoft. Organizations use DotNetNuke to quickly develop and deploy interactive and dynamic web sites, intranets, extranets and web applications. The DotNetNuke platform is available in a free Community and subscription-based Professional and Enterprise Editions with an Elite Support option. DotNetNuke Corp. also operates the DotNetNuke Store where users purchase third party apps for the platform.