Getting Started With Microsoft SQL Server 2000 Desktop Engine
Installation

Microsoft SQL Server is expensive commercial software, but you can download Microsoft SQL Server 2000 Desktop Engine for free from http://www.microsoft.com/sql/msde/downloads/download.asp. MSDE is a stripped down version of SQL Server that's good for testing software that will ultimately run against SQL Server.

I've successfully installed and used MSDE 2000 A on Windows XP. I haven't tried to run it on any other platform.

Read the instructions on the page and download the file to your desktop. It should be called something MSDE2000A.exe or something similar.

To unpack MSDE 2000, double-click MSDE2000A.exe. When prompted with a license agreement, click "I Agree". Click "Finish" to unpack the distribution in C:\MSDERelA. If prompted with "The specified output folder does not exist. Create it?" Click "Yes". Extraction will proceed and a progress bar will keep you informed of the extraction progress. Ultimately a dialog will appear indicating that "The packages have been delivered successfully." Click OK.

To install an instance of MSDE 2000, open a command prompt and type:

cd C:\MSDERelA
setup sapwd="sapassword" disablenetworkprotocols=0 securitymode=sql

This command creates an instance of MSDE with an administrative user named sa with password sapassword. The disablenetworkprotocols=0 switch configures the instance to allow connections from remote hosts on tcp port 1433. The securitymode=sql switch configures the instance to use "Mixed Mode" which allows users to log in using Windows or SQL Authentication modes.

After a reboot, MSDE should be up and running.

Creating a Database

Log in using the following command. When it promts you for a password, type sapassword.

osql -U sa -S localhost

Though you could create your own tables using the sa user and the system database, it's not a good idea. You should create a user database. The following commands create a database named testdb and switch the current database to testdb.

create database testdb
go
use testdb
go

Creating a user is a 2 step process. First a universal login must be created, then it must be added as a user to a particular database. Execute the following stored procedures and queries to create a login named testuser with password testpassword, add it as a user of testdb and give it all permissions.

sp_addlogin "testuser","testpassword"
go
sp_adduser "testuser"
go
grant all to testuser
go
quit

Now you can log in as testuser using the following command. When promted for a password, enter testpassword.

osql -U testuser -S localhost -D testdb

This should be enough to get you started.

Accessing a Database

Now, if you log out and log back in, you can access the database using the osql client as follows.

osql -U testuser -S localhost

Once you're connected, the osql client prompts you to enter a query. First you should "use" a particular database, then you can run queries. Queries may be split across multiple lines. To run a query, type go on a line by itself. To exit, type quit on a line by itself.

A sample isqlsession follows.

osql -U testuser -S localhost
Password: 
1> use testdb
2> go
1> create table testtable (
2> col1 char(40),
3> col2 integer
4> )
5> go
1> select name from sysobjects where type='U'
2> go
 name                           
 ------------------------------ 
 testtable                      

(1 row affected)
1> insert into testtable values ('hello',50)
2> go
(1 row affected)
1> insert into testtable values ('hi',60)
2> go
(1 row affected)
1> insert into testtable values ('bye',70)
2> go
(1 row affected)
1> select * from testtable
2> go
 col1                                     col2        
 ---------------------------------------- ----------- 
 hello                                             50 
 hi                                                60 
 bye                                               70 

(3 rows affected)
1> update testtable set col2=0 where col1='hi'
2> go
(1 row affected)
1> select * from testtable
2> go
 col1                                     col2        
 ---------------------------------------- ----------- 
 hello                                             50 
 hi                                                 0 
 bye                                               70 

(3 rows affected)
1> delete from testtable where col2=50
2> go
(1 row affected)
1> select * from testtable
2> go
 col1                                     col2        
 ---------------------------------------- ----------- 
 hi                                                 0 
 bye                                               70 

(2 rows affected)
1> drop table testtable
2> go
1> quit
Accessing a Database With SQL Relay

Accessing MSDE from SQL Relay requires an instance entry in your sqlrelay.conf file for the database that you want to access. Here is an example sqlrelay.conf which defines an SQL Relay instance called msdetest. This instance connects to the testdb database on the server msde as the user testuser with password testpassword.

<?xml version="1.0"?>
<!DOCTYPE instances SYSTEM "sqlrelay.dtd">
<instances>

        <instance id="msdetest" port="9000" socket="/tmp/msdetest.socket" dbase="freetds" connections="3" maxconnections="5" maxqueuelength="0" growby="1" ttl="60" endofsession="commit" sessiontimeout="600" runasuser="nobody" runasgroup="nobody" cursors="5">
                <users>
                        <user user="msdetest" password="msdetest"/>
                </users>
                <connections>
                        <connection connectionid="msdetest" string="server=msde;db=testdb;user=testuser;password=testpassword;" metric="1"/>
                </connections>
        </instance>

</instances>

Note that the server=msde parameter does not refer to a host named msde. Rather it refers to an entry in the freetds.conf file. For example, the following freetds.conf entry defines a server named msde on the host remotehost running on port 1433.

[msde]
	host = remotehost
	port = 1433
	tds version = 8.0

Now you can start up this instance with the following command.

sqlr-start -id msdetest

Note that there are a couple of common problems people have with the FreeTDS connection. See the FAQ and the common problems section of the document on running SQL Relay for more info.

To connect to the instance and run queries, use the following command.

sqlrsh -id msdetest

The following command shuts down the SQL Relay instance.

sqlr-stop msdetest