Connect to sqlserver through osql

Source: Internet
Author: User
<Doctype HTML public-wcdtd XHTML stricten httpwwwworgtrxhtmldtdxhtml-strictdtd>

The sqlserver2000 query analyzer only supports 64 K scripts. Therefore, it is impossible to import data using insert. SQL scripts. You can use the osql command to connect to the script file and execute the script.
Usage: osql [-u logon id] [-P Password]
[-S server] [-H host name] [-e trusted connection]
[-D use the database name] [-l logon timeout value] [-T query timeout value]
[-H title] [-s column separator] [-W column width]
[-A packet size] [-e echo input] [-I allows a quoted identifier]
[-L list servers] [-C command end] [-d odbc dsn name]
[-Q "command line query"] [-Q "command line query" and exit]
[-N delete number method] [-M error level]
[-R messages sent to stderr] [-V severity level]
[-I input file] [-O output file]
[-P print statistics] [abort batch processing when a-B error occurs]
[-X [1] disable command, [display a warning when exiting]
[-O use the old iSQL to disable the following items]
<EOF> Batch Processing
Auto Adjust console width
Wide message
The default error levels are-1 and 1.
[-? Show syntax Summary]

Command Line operations are sometimes more efficient than using the mouse in the graphic interface. Therefore, you are familiar with common command line operations. The following describes the SQL server command line tools iSQL and osql.

The iSQL utility allows you to enter Transact-SQL statements, system processes, and script files, and use DB-library to communicate with SQL Server 2000.

Osql utility allows you to enter Transact-SQL statements, system processes, and script files. The utility communicates with the server through ODBC.

& #9670; trusted connection:
> ISQL-e
Or
> Osql-e

& #9670; view all databases:
Use master
Exec sp_helpdb
Go

& #9670; view database pubs:
Use master
Exec sp_helpdb pubs
Go

& #9670; view objects in database pubs:
Use pubs
Exec sp_help
Go
Equivalent to select table_name from user_objects of Oracle;

& #9670; view the table employee structure in the database pubs:
Use pubs
Exec sp_help employee
Go
Equivalent to desc employees in Oracle SQL * Plus

& #9670; select statement:
Use pubs
Select * from employee
Go

& #9670; when a single quotation mark is used to separate a character constant that includes an embedded single quotation mark, two single quotation marks are used to indicate the embedding of single quotation marks. For example:
Select 'O' Leary'
Go

& #9670; use 7. Double quotation marks to enclose double quotation marks. For example:
Select 'o "Leary'
Go

& #9670; SQL Server database information query
Use master
Exec sp_helpdb pubs
Go
Or:
Use master
Select name, dbid from sysdatabases
Go

& #9670; query database objects (equivalent to Oracle's select * From user_tables ;)
Use pubs
Exec sp_help
Go
Or
Use master
Select name, ID from pubs. DBO. sysobjects where type = 'U'
Go

& #9670; query fields (equivalent to desc employees in Oracle SQL * Plus)
Use pubs
Exec sp_help employee
Go

& #9670; view the specified
Use pubs
Select name, ID, xtype, Length
From syscolumns where id = 277576027
Go

Use pubs
Select *
From syscolumns where id = 277576027
Go

& #9670; view the definition of the Data Type name:
Select name, xtype
From policypes
Go

& #9670; start "query analyzer" from the command line"
> Isqlw

& #9670; iSQL command description
All the statements that go enters after executing the last go command.
Reset clears all input statements.
Ed calls the editor.
!! Command to execute the operating system command.
Quit or exit () to exit iSQL.
CTRL + C ends the query without exiting iSQL.
Only when the command Terminator go (default), reset, Ed ,!! Exit, quit, and CTRL + C can be recognized only when a row starts (followed by the iSQL prompt. ISQL ignores any content entered after these keywords in the same row.

# Database Technology

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.