Skip to main content

Posts

Showing posts from September, 2010

Execute *.sql with .NET

Do you ever want to execute slq statements at once. I mean SQL Script file. Normally we are using like following commands to Execute Single SQL statement. SqlCommand cmd = new SqlCommand(sSQL, conn); cmd.ExecuteNonQuery(); cmd.Dispose(); but this way you can execute one command at a time. We cannot execute SQL script using above command. Normal SQL Script Like this. if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK__titleauth__au_id__0519C6AF]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1) ALTER TABLE [dbo].[titleauthor] DROP CONSTRAINT FK__titleauth__au_id__0519C6AF GO CREATE TABLE [dbo].[authors] ( [au_id] [id] NOT NULL , [au_lname] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [au_fname] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [phone] [char] (12) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL , [address] [varchar] (40) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [city] [varchar] (20) COLL