how to execute a SQL statement

I am working on a windows XP sp3, DELL optiplex computer.  I have installed some software for a group home, called PPS, which is a database software suite.  It required that I installed SQL server 2005, as part of the install.  The install has been completed successfully.

Next, I moved on to copying the data for the database, from the prior machine/workstation into the appropriate spot.  I was able to correctly copy the files to the correct location, after stopping the SQL services.  I rebooted, and made sure the services started again, as they are set for automatic.

Now, i am left with one last step.  I am being asked to execute a SQL statement that says:  

sp_attach_db 'PPData', 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PPData.mdf', 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PPData_Log.ldf'

The location of the files has been updated for the new machine, and is accurate.  However, when I try to execute the command from the run prompt it says:

Windows cannot find 'sp_attach_db'.  Make sure you typed the name correctly ...

Can you execute SQL statements from the run command in windows XP.  If not, how would I go about executing this statement so that the database application, PPS, can see the data I have copied in.  I cannot see the data until it has been attached.
Who is Participating?
Alpesh PatelConnect With a Mentor Assistant ConsultantCommented:
You wizard for that. Select MDF file and do it.

Attach DB
Try this:
isql -E -d master -Q "exec sp_attach_db 'PPData', 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PPData.mdf', 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PPData_Log.ldf'"

Open in new window

becraigConnect With a Mentor Commented:
Why not do this from the gui

go to Sql server management studio.
connect to the database server
Expand databases
right click on any and attach db then point to your mdf file.

that should work.
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

Are you doing it in SQL Server Management Studio? Is SSMS installed. SSMS is a client application to connect to sql server engines and run t-sql query and to perform other tasks as monitoring, adminstration, etc. So, install SSMS and run the command.

You can also use sqlcmdutility for this. However, my recommendation will still be SSMS first.
Ugo MenaCommented:
Yes you can execute SQL statements from the command line.

The sp_attach_db was deprecated in SQL 2005. To attach your DB use the following:
USE master;
      ON (FILENAME = 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PPData.mdf''),
    (FILENAME = C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\PPData_Log.ldf')

For more reference:
redemption7Author Commented:
Hey ultralites,

Thank you very much for your help.  Should i put the code you sent into a NotePad file/text file, and then try to run it, or should i try to type that as one big command.  If i do it in NotePad, what should the file extension be ?  Thank you.

Also, as far as GUI software goes, i can only see the sql server configuration manager tool, not the GUI mentioned above.
Ugo MenaCommented:
Yes, you should save the code as a script. Then to execute the script use the sqlcmd command from the command prompt.

The format is:

sqlcmd -S [server_name] -U [login_user_name] -P [login_password] -i [full_path_of_sql_file_that_will_be_executed] -o [full_path_of_output_file_after_sql_executed]

For example: to run an SQL file named "script.sql" that is on root drive C and get output results. From the command prompt you would type:

sqlcmd -S yourserver name,1433\MSSQLSERVER -U sa -P password -i C:\script.sql -o C:\output-script.txt

After "script.sql" is executed, there's a new file named "output-script.txt". Check after executing "script.sql" to view the results.
Joseph OLoughlinIT Support SpecialistCommented:
Please let us know what's listed in Add and Remove Programs.
Is it MSDE or SQL Express or ...
Not all versions of MS SQL come with TSQL to allow command execution from the command prompt.
I've requested that this question be deleted for the following reason:

Not enough information to confirm an answer.
redemption7Author Commented:
Thank you all for your help, and sorry in the delay in closing this out.  I am not often onsite here.  I was able to download and install the management studio software, and use the GUI to attach the database.  I appreciate everyone's help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.