Solved

How do you run a script file against an operating sqlexpress 2008 database

Posted on 2009-05-07
7
319 Views
Last Modified: 2012-05-06
How do you run a script file against an operating sqlexpress 2008 database
0
Comment
Question by:gracemedia
  • 3
  • 3
7 Comments
 
LVL 26

Expert Comment

by:Chris Luttrell
ID: 24331204
Through either Management Studio or SQLCMD at the command line.
(Link for SQL Server Management Studio Express http://msdn.microsoft.com/en-us/library/ms365247.aspx)
0
 
LVL 8

Expert Comment

by:k_rasuri
ID: 24331207
What scrip are you talking about. if you are taking about using sql server query file click on Programs ->management studio -> click on Query Analyzer

if you are taking about running some command line script file..check this

http://www.databasejournal.com/features/mssql/article.php/3654176/SQL-Server-2005-Command-Line-Tool-SQLCMD--Part-I.htm
0
 
LVL 2

Author Comment

by:gracemedia
ID: 24331319
how do you do it through Management Studio?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 8

Expert Comment

by:k_rasuri
ID: 24331444
i dont know what kind of file are you talking about...is this just a sql script. then you can use Query Analyzer.

if you want to do some administration tasks..you can use SQLCMD tool (check the link i pasted earlier)
0
 
LVL 2

Author Comment

by:gracemedia
ID: 24331587
It is a .sql file
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_CuteChat4_SupportAgent_CuteChat4_SupportDepartment]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)

ALTER TABLE [dbo].[CuteChat4_SupportAgent] DROP CONSTRAINT FK_CuteChat4_SupportAgent_CuteChat4_SupportDepartment

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_InstantMessage]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_InstantMessage]

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_Lobby]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_Lobby]

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_LogEvent]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_LogEvent]

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_LogMessage]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_LogMessage]

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_Portal]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_Portal]

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_Rule]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_Rule]

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_Settings]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_Settings]

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_SupportAgent]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_SupportAgent]

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_SupportCustomer]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_SupportCustomer]

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_SupportDepartment]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_SupportDepartment]

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_SupportFeedback]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_SupportFeedback]

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_SupportMessage]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_SupportMessage]

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_SupportSession]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_SupportSession]

GO
 

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[CuteChat4_User]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)

drop table [dbo].[CuteChat4_User]

GO
 

CREATE TABLE [dbo].[CuteChat4_InstantMessage] (

	[MessageId] [int] IDENTITY (1, 1) NOT NULL ,

	[MsgTime] [datetime] NOT NULL ,

	[Sender] [nvarchar] (100) NOT NULL ,

	[SenderId] [nvarchar] (100) NOT NULL ,

	[Target] [nvarchar] (100) NOT NULL ,

	[TargetId] [nvarchar] (100) NOT NULL ,

	[Offline] [int] NOT NULL ,

	[DeletedBySender] [int] NULL ,

	[DeletedByTarget] [int] NULL ,

	[IPAddress] [nvarchar] (25) NOT NULL ,

	[Text] [ntext] NULL ,

	[Html] [ntext] NULL 

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
 

CREATE TABLE [dbo].[CuteChat4_Lobby] (

	[LobbyId] [int] IDENTITY (1, 1) NOT NULL ,

	[Title] [nvarchar] (50) NOT NULL ,

	[Topic] [nvarchar] (200) NOT NULL ,

	[Announcement] [ntext] NOT NULL ,

	[Locked] [bit] NOT NULL ,

	[AllowAnonymous] [bit] NOT NULL ,

	[Password] [nvarchar] (50) NOT NULL ,

	[Description] [nvarchar] (400) NOT NULL ,

	[Integration] [nvarchar] (200) NOT NULL ,

	[ManagerList] [ntext] NOT NULL ,

	[MaxOnlineCount] [int] NOT NULL ,

	[MaxIdleMinute] [int] NOT NULL ,

	[AutoAwayMinute] [int] NOT NULL ,

	[HistoryCount] [int] NOT NULL ,

	[HistoryDay] [int] NOT NULL ,

	[SortIndex] [int] NOT NULL 

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
 

CREATE TABLE [dbo].[CuteChat4_LogEvent] (

	[EventId] [int] IDENTITY (1, 1) NOT NULL ,

	[EvtTime] [datetime] NOT NULL ,

	[Category] [nvarchar] (50) NOT NULL ,

	[Message] [nvarchar] (3000) NOT NULL ,

	[Portal] [nvarchar] (50) NOT NULL ,

	[Place] [nvarchar] (50) NOT NULL ,

	[UserName] [nvarchar] (50) NULL ,

	[UserId] [nvarchar] (50) NULL 

) ON [PRIMARY]

GO
 

CREATE TABLE [dbo].[CuteChat4_LogMessage] (

	[MessageId] [int] IDENTITY (1, 1) NOT NULL ,

	[MsgTime] [datetime] NOT NULL ,

	[Location] [nvarchar] (50) NOT NULL ,

	[Place] [nvarchar] (50) NOT NULL ,

	[Sender] [nvarchar] (100) NULL ,

	[SenderId] [nvarchar] (100) NULL ,

	[Target] [nvarchar] (100) NULL ,

	[TargetId] [nvarchar] (100) NULL ,

	[Whisper] [int] NOT NULL ,

	[IPAddress] [nvarchar] (25) NOT NULL ,

	[Text] [ntext] NULL ,

	[Html] [ntext] NULL 

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
 

CREATE TABLE [dbo].[CuteChat4_Portal] (

	[PortalName] [nvarchar] (50) NOT NULL ,

	[Properties] [ntext] NULL 

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
 

CREATE TABLE [dbo].[CuteChat4_Rule] (

	[RuleId] [int] IDENTITY (1, 1) NOT NULL ,

	[Category] [nvarchar] (50) NOT NULL ,

	[SortIndex] [int] NOT NULL ,

	[RuleMode] [nvarchar] (50) NOT NULL ,

	[Expression] [nvarchar] (50) NOT NULL ,

	[Disabled] [bit] NOT NULL 

) ON [PRIMARY]

GO
 

CREATE TABLE [dbo].[CuteChat4_Settings] (

	[SettingName] [nvarchar] (50) NOT NULL ,

	[SettingData] [ntext] NOT NULL 

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
 

CREATE TABLE [dbo].[CuteChat4_SupportAgent] (

	[DepartmentId] [int] NOT NULL ,

	[AgentUserId] [nvarchar] (50) NOT NULL 

) ON [PRIMARY]

GO
 

CREATE TABLE [dbo].[CuteChat4_SupportCustomer] (

	[CustomerId] [nvarchar] (50) NOT NULL ,

	[CustomerData] [ntext] NULL 

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
 

CREATE TABLE [dbo].[CuteChat4_SupportDepartment] (

	[DepartmentId] [int] IDENTITY (1, 1) NOT NULL ,

	[DepartmentName] [nvarchar] (50) NOT NULL 

) ON [PRIMARY]

GO
 

CREATE TABLE [dbo].[CuteChat4_SupportFeedback] (

	[FeedbackId] [int] IDENTITY (1, 1) NOT NULL ,

	[FbTime] [datetime] NOT NULL ,

	[CustomerId] [nvarchar] (100) NULL ,

	[DisplayName] [nvarchar] (100) NULL ,

	[Name] [nvarchar] (100) NOT NULL ,

	[Email] [nvarchar] (100) NOT NULL ,

	[Title] [nvarchar] (200) NOT NULL ,

	[Content] [ntext] NOT NULL ,

	[Comment] [ntext] NULL ,

	[CommentBy] [nvarchar] (100) NULL 

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
 

CREATE TABLE [dbo].[CuteChat4_SupportMessage] (

	[MessageId] [int] IDENTITY (1, 1) NOT NULL ,

	[MsgTime] [datetime] NOT NULL ,

	[SessionId] [int] NOT NULL ,

	[MsgType] [nvarchar] (50) NOT NULL ,

	[Sender] [nvarchar] (100) NULL ,

	[SenderId] [nvarchar] (100) NULL ,

	[Target] [nvarchar] (100) NULL ,

	[TargetId] [nvarchar] (100) NULL ,

	[Text] [ntext] NULL ,

	[Html] [ntext] NULL 

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
 

CREATE TABLE [dbo].[CuteChat4_SupportSession] (

	[SessionId] [int] IDENTITY (1, 1) NOT NULL ,

	[BeginTime] [datetime] NOT NULL ,

	[DepartmentId] [int] NOT NULL ,

	[AgentUserId] [nvarchar] (100) NOT NULL ,

	[CustomerId] [nvarchar] (100) NOT NULL ,

	[DisplayName] [nvarchar] (100) NOT NULL ,

	[ActiveTime] [datetime] NOT NULL ,

	[Email] [nvarchar] (50) NULL ,

	[IPAddress] [nvarchar] (50) NOT NULL ,

	[Culture] [nvarchar] (50) NOT NULL ,

	[Platform] [nvarchar] (50) NOT NULL ,

	[Browser] [nvarchar] (50) NOT NULL ,

	[AgentRating] [int] NOT NULL ,

	[SessionData] [ntext] NULL 

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
 

CREATE TABLE [dbo].[CuteChat4_User] (

	[UserId] [nvarchar] (50) NOT NULL ,

	[DisplayName] [nvarchar] (100) NULL ,

	[Description] [nvarchar] (300) NULL ,

	[BuildinIgnores] [ntext] NULL ,

	[BuildinContacts] [ntext] NULL ,

	[ServerProperties] [ntext] NULL ,

	[PublicProperties] [ntext] NULL ,

	[PrivateProperties] [ntext] NULL 

) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]

GO
 

ALTER TABLE [dbo].[CuteChat4_InstantMessage] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_InstantMessage] PRIMARY KEY  CLUSTERED 

	(

		[MessageId]

	)  ON [PRIMARY] 

GO
 

ALTER TABLE [dbo].[CuteChat4_Lobby] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_Lobby] PRIMARY KEY  CLUSTERED 

	(

		[LobbyId]

	)  ON [PRIMARY] 

GO
 

ALTER TABLE [dbo].[CuteChat4_LogEvent] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_LogEvent] PRIMARY KEY  CLUSTERED 

	(

		[EventId] DESC 

	)  ON [PRIMARY] 

GO
 

ALTER TABLE [dbo].[CuteChat4_LogMessage] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_LogMessage] PRIMARY KEY  CLUSTERED 

	(

		[MessageId]

	)  ON [PRIMARY] 

GO
 

ALTER TABLE [dbo].[CuteChat4_Portal] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_Portal] PRIMARY KEY  CLUSTERED 

	(

		[PortalName]

	)  ON [PRIMARY] 

GO
 

ALTER TABLE [dbo].[CuteChat4_Rule] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_Rule] PRIMARY KEY  CLUSTERED 

	(

		[RuleId]

	)  ON [PRIMARY] 

GO
 

ALTER TABLE [dbo].[CuteChat4_Settings] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_Settings] PRIMARY KEY  CLUSTERED 

	(

		[SettingName]

	)  ON [PRIMARY] 

GO
 

ALTER TABLE [dbo].[CuteChat4_SupportAgent] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_SupportAgent] PRIMARY KEY  CLUSTERED 

	(

		[DepartmentId],

		[AgentUserId]

	)  ON [PRIMARY] 

GO
 

ALTER TABLE [dbo].[CuteChat4_SupportCustomer] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_SupportCustomer] PRIMARY KEY  CLUSTERED 

	(

		[CustomerId]

	)  ON [PRIMARY] 

GO
 

ALTER TABLE [dbo].[CuteChat4_SupportDepartment] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_SupportDepartment] PRIMARY KEY  CLUSTERED 

	(

		[DepartmentId]

	)  ON [PRIMARY] 

GO
 

ALTER TABLE [dbo].[CuteChat4_SupportFeedback] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_SupportFeedback] PRIMARY KEY  CLUSTERED 

	(

		[FeedbackId]

	)  ON [PRIMARY] 

GO
 

ALTER TABLE [dbo].[CuteChat4_SupportMessage] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_SupportMessage] PRIMARY KEY  CLUSTERED 

	(

		[MessageId]

	)  ON [PRIMARY] 

GO
 

ALTER TABLE [dbo].[CuteChat4_SupportSession] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_SupportSession] PRIMARY KEY  CLUSTERED 

	(

		[SessionId]

	)  ON [PRIMARY] 

GO
 

ALTER TABLE [dbo].[CuteChat4_User] WITH NOCHECK ADD 

	CONSTRAINT [PK_CuteChat4_User] PRIMARY KEY  CLUSTERED 

	(

		[UserId]

	)  ON [PRIMARY] 

GO
 

 CREATE  INDEX [IX_CuteChat4_InstantMessage] ON [dbo].[CuteChat4_InstantMessage]([MsgTime], [Sender], [SenderId], [Target], [TargetId], [Offline], [IPAddress]) ON [PRIMARY]

GO
 

ALTER TABLE [dbo].[CuteChat4_Lobby] ADD 

	CONSTRAINT [DF_CuteChat4_Lobby_AllowAnonymous] DEFAULT (1) FOR [AllowAnonymous],

	CONSTRAINT [DF_CuteChat4_Lobby_Password] DEFAULT ('') FOR [Password],

	CONSTRAINT [DF_CuteChat4_Lobby_Description] DEFAULT (N'') FOR [Description],

	CONSTRAINT [DF_CuteChat4_Lobby_Integration] DEFAULT (N'') FOR [Integration],

	CONSTRAINT [DF_CuteChat4_Lobby_AutoAwayMinute] DEFAULT (5) FOR [AutoAwayMinute]

GO
 

 CREATE  INDEX [IX_CuteChat4_LogEvent] ON [dbo].[CuteChat4_LogEvent]([EvtTime], [Category], [Portal], [Place], [UserName], [UserId]) ON [PRIMARY]

GO
 

ALTER TABLE [dbo].[CuteChat4_LogMessage] ADD 

	CONSTRAINT [DF_CuteChat4_LogMessage_Location] DEFAULT (N'Lobby') FOR [Location]

GO
 

 CREATE  INDEX [IX_CuteChat4_LogMessage] ON [dbo].[CuteChat4_LogMessage]([MsgTime], [Location], [Place]) ON [PRIMARY]

GO
 

ALTER TABLE [dbo].[CuteChat4_SupportSession] ADD 

	CONSTRAINT [DF_CuteChat4_SupportSession_AgentRating] DEFAULT (0) FOR [AgentRating]

GO
 

 CREATE  INDEX [IX_CuteChat4_SupportSession_CustomerId] ON [dbo].[CuteChat4_SupportSession]([CustomerId]) ON [PRIMARY]

GO
 

 CREATE  INDEX [IX_CuteChat4_SupportSession_Query] ON [dbo].[CuteChat4_SupportSession]([BeginTime], [DepartmentId], [AgentUserId], [CustomerId]) ON [PRIMARY]

GO
 

ALTER TABLE [dbo].[CuteChat4_SupportAgent] ADD 

	CONSTRAINT [FK_CuteChat4_SupportAgent_CuteChat4_SupportDepartment] FOREIGN KEY 

	(

		[DepartmentId]

	) REFERENCES [dbo].[CuteChat4_SupportDepartment] (

		[DepartmentId]

	) ON DELETE CASCADE 

GO

Open in new window

0
 
LVL 8

Accepted Solution

by:
k_rasuri earned 500 total points
ID: 24331614

All Programs -> SQL Server Management studio ->

Connect to the server
click on File ->Open -> File -> find the file and open

In the databases select the right database from the dropdown list
0
 
LVL 2

Author Closing Comment

by:gracemedia
ID: 31579237
Thank you for your time.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
Learn about cloud computing and its benefits for small business owners.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now