Select the product you need help with
How to manage the SQL Server Desktop Engine (MSDE 2000) or SQL Server 2005 Express Edition by using the osql utilityArticle ID: 325003 - View products that this article applies to. This article was previously published under Q325003 On This PageSUMMARY
The SQL Server Desktop Engine (also known as MSDE 2000) does not have its own user interface because it is primarily designed to run in the background. Users interact with MSDE 2000 through the program in which it is embedded. The only tool that is provided with MSDE 2000 is the osql utility. The executable file, Sql.exe, is located in the MSSQL\Binn folder for a default instance of MSDE 2000. This article focuses on how to manage MSDE 2000 by using the osql utility. If you are using SQL Server 2005, you can also use the osql utility to manage SQL Server 2005 Express Edition. However, this feature will be removed in a future version of Microsoft SQL Server 2005. We recommend that you do not use this feature in new development work and plan to modify applications that currently use the feature. Use the Sqlcmd utility instead. For more information about how to use the Sqlcmd utility, visit the following Microsoft Developer Network (MSDN) Web site: http://msdn2.microsoft.com/en-us/library/ms170207.aspx
(http://msdn2.microsoft.com/en-us/library/ms170207.aspx)
What is Osql?The osql utility is a Microsoft Windows 32 command prompt utility that you can use to run Transact-SQL statements and script files. The osql utility uses the ODBC database application programming interface (API) to communicate with the server.How Do You Use Osql?Typically, you use the osql utility these ways:
Interactively Enter Transact-SQL StatementsTo display a list of the case-sensitive options of the osql utility, type the following at a command prompt, and then press ENTER:osql -? For more information about each option of the osql utility, see the "osql Utility" topic in SQL Server Books Online. To interactively enter Transact-SQL statements, follow these steps:
Submit an Osql JobTypically, you submit an osql job one of two ways. You can either:
Specify a Single Transact-SQL Statement To run a Transact-SQL statement against the local default instance of MSDE 2000, type a command similar to this one osql -E -q "Transact-SQL statement" where
Point the Utility to a Script File To point the utility to a script file, follow these steps:
Connect to SQL Server Desktop Engine (MSDE 2000)To connect to MSDE 2000, follow these steps:
Manage MSDE 2000The remaining sections of this article introduce you briefly to the Transact-SQL commands most frequently used to manage MSDE 2000.Create a New LoginA user cannot connect to SQL Server without providing a valid login id. The sp_grantlogin stored procedure is used to authorize a Microsoft Windows network account (either a group or a user account) for use as a SQL Server login for connecting to an instance of SQL Server by using Windows Authentication. The following example permits a Windows NT user named Corporate\Test to connect to a SQL Server instance:For more information about the sp_grantlogin stored procedure, see the "sp_grantlogin, Transact-SQL Reference" topic in SQL Server Books Online. You use the sp_addlogin stored procedure to create a new login account for SQL Server connections by using SQL Server Authentication. The following example creates a SQL Server login for a user named "test" with a password of "hello": Access a DatabaseAfter a users connects to an instance of SQL Server, they cannot perform activities in a database until the dbo grants them access to the database. You can use the sp_grantdbaccess stored procedure to add a security account for a new user to the current database. The following example adds an account for a Microsoft Windows NT user named Corporate\BobJ to the current database and names it "Bob":The sp_adduser stored procedure performs the same function as the sp_grantdbaccess stored procedure. Because, the sp_adduser stored procedure is included for backward compatibility, Microsoft recommends that you use the sp_grantdbacess stored procedure. Only members of the sysadmin fixed server role, the db_accessadmin and the db_owner fixed database roles can run the sp_grantdbaccess stored procedure. For more information about the sp_grantdbaccess stored procedure, see the "sp_grantdbaccess, Transact-SQL Reference" topic in SQL Server Books Online. How to Change the Password for a LoginTo change the password of a login, use the sp_password stored procedure. The following example changes the password for the login "test" from "ok" to "hello":Execute permissions default to the public role for a user that is changing the password for his or her own login. Only members of the sysadmin role can change the password for another user's login. For more information about the sp_password stored procedure, see the "sp_password, Transact-SQL Reference" topic in SQL Server Books Online Create a DatabaseA MSDE 2000 database is made up of a collection of tables that contain data and other objects, such as views, indexes, stored procedures, and triggers, which are defined to support activities performed with the data. To create a MSDE 2000 database, use the "CREATE DATABASE" Transact-SQL command. For more information about creating a database, see the "Creating a Database" topic in SQL Server Books Online.The following example creates a database named Test. Because no additional parameters are added to the command, the Test database will be the same size as the model database: To create a new database object, use the CREATE Transact-SQL command. For example, to create a new table, use the "CREATE TABLE" Transact-SQL command. For more information, refer to SQL Server Books Online. Back Up and Restore DatabasesThe backup and restore component of SQL Server provides an important safeguard for protecting critical data stored in SQL Server databases.With proper planning, you can recover from many failures, including:
For more information about database backup and restore operations, see the "Backing Up and Restoring Databases" topic in SQL Server Books Online. The following example performs a full database backup for a database named mydb, names the backup Mydb.bak, and then stores the backup in the C:\Msde\Backup folder: The following example performs a log backup for a database named mydb, names the backup Mydb_log.bak, and then stores it in the C:\Msde\Backup folder: BACKUP DATABASE and BACKUP LOG permissions default to members of the sysadmin fixed server role and the db_owner and db_backupoperator fixed database roles. For more information about the BACKUP statement, see the "BACKUP, Transact-SQL Reference" topic in SQL Server Books Online. MSDE includes the SQL Server Agent Service for managing scheduled jobs. For example, you can create and schedule a Transact-SQL backup job. The SQL Server Agent Service manages the job scheduling. For sample code about how to use the various stored procedures with MSDE 2000 to perform a backup and schedule the backup, see the following article in the Microsoft Knowledge Base: 241397
For more information about the SQL Server Agent Service, see the "SQL Server Agent Service" topic in SQL Server Books Online.
(http://support.microsoft.com/kb/241397/EN-US/
)
How To Back Up a Microsoft Data Engine Database with Transact-SQL
Backing up a database is only half of the process. It is important to know how to restore the database from a backup. The following example restores a database that is named mydb from the backup file C:\Msde\Backup\Mydb.bak: Attach and Detach a DatabaseThe data and transaction log files of a database can be detached and then reattached to another server, or even to the same server. Detaching a database removes the database from SQL Server but leaves the database intact in the data and transaction log files that compose the database. You can then use these data and transaction log files to attach the database to any instance of SQL Server, including the server from which the database was detached. This makes the database available in exactly the same state it was in when it was detached. For more information, see the "Attaching and Detaching a Database" topic in SQL Server Books Online.The following example detaches a database named mydb from the current instance of SQL Server: The following example attaches two files from a database named mydb to the current instance of SQL Server: 239530
Only members of the sysadmin and the dbcreator fixed server roles can run this procedure. For more information about the sp_attach_db stored procedure, see the "sp_attach_db, Transact-SQL Reference" topic in SQL Server Books Online.
(http://support.microsoft.com/kb/239530/EN-US/
)
INF: Unicode String Constants in SQL Server Require N Prefix
The following information about the use of the osql utility also applies to all editions of Microsoft SQL Server 2000. REFERENCES
To download an updated version of the SQL Server 2000 Books Online, visit the following Microsoft Web site:
http://technet.microsoft.com/en-us/sqlserver/bb331756.aspx
To download the SQL Server 7.0 version of SQL Server Books Online, visit the following Microsoft Web site:
(http://technet.microsoft.com/en-us/sqlserver/bb331756.aspx)
http://download.microsoft.com/download/SQL70/File/2/Win98/En-US/SQLBOL.exe
For more information about MSDE 2000, see the following articles in the Microsoft Knowledge Base:
(http://download.microsoft.com/download/sql70/file/2/win98/en-us/sqlbol.exe)
319930
(http://support.microsoft.com/kb/319930/
)
How to connect to an instance of SQL Server Desktop Edition or of SQL Server 2005 Express Edition
241397
(http://support.microsoft.com/kb/241397/EN-US/
)
How To Back Up a Microsoft Desktop Engine Database with Transact-SQL
PropertiesArticle ID: 325003 - Last Review: November 14, 2007 - Revision: 2.3 APPLIES TO
| Article Translations
|



Back to the top








