?
Solved

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

Posted on 2009-05-07
7
Medium Priority
?
335 Views
Last Modified: 2012-05-06
How do you run a script file against an operating sqlexpress 2008 database
0
Comment
Question by:gracemedia
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 27

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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

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…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Suggested Courses

765 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