Thursday 9 June 2011

SQL Server 2000 Command Line Utilities

Ø      SQL Server 2000 command line utilities primarily used for diagnostic, configuration and data migration purposes.
osql Utility
If you have repetitive tasks to run, multiple SQL servers to administer, or a very large sequence of commands to execute, then the OSQL utility may be the tool to use. OSQL is capable of running both scripts and interactive commands. It is started from the command line and can be executed manually or by a scheduled task. With over twenty-five switch commands, OSQL can usually be configured to execute, as your application requires.
Syntax
osql -U login_id [-e] [-E] [-p] [-n] [-d db_name] [-Q "query"] [-q "query"]
[-c cmd_end] [-h headers] [-w column_width] [-s col_separator]
[-t time_out] [-m error_level] [-I] [-L] [-?] [-r {0 | 1}]
[-H wksta_name] [-P password] [-R]
[-S server_name] [-i input_file] [-o output_file] [-u] [-a packet_size]
[-b] [-O] [-l time_out]
Arguments
-U login_id
Is the user login ID. Login IDs are case-sensitive.
-e
Echoes input.
-E
Uses a trusted connection instead of requesting a password.
-p
Prints performance statistics.
-n
Removes numbering and the prompt symbol (>) from input lines.
-d db_name
Issues a USE db_name statement when osql is started.
-Q "query"
Executes a query and immediately exits osql. Use double quotation marks around the query and single quotation marks around anything embedded in the query.
-q "query"
Executes a query when osql starts, but does not exit osql when the query completes. (Note that the query statement should not include GO). If you issue a query from a batch file, use %variables, or environment %variables%. For example:
SET table = sysobjects
osql /q "Select * from %table%"
Use double quotation marks around the query and single quotation marks around anything embedded in the query.
-c cmd_end
Specifies the command terminator. By default, commands are terminated and sent to Microsoft® SQL Server™ by entering GO on a line by itself. When you reset the command terminator, do not use SQL reserved words or characters that have special meaning to the operating system, whether preceded by a backslash or not.
-h headers
Specifies the number of rows to print between column headings. The default is to print headings one time for each set of query results. Use -1 to specify that no headers will be printed. If using -1, there must be no space between the parameter and the setting (-h-1, not -h -1).
-w column_width
Allows the user to set the screen width for output. The default is 80 characters. When an output line has reached its maximum screen width, it is broken into multiple lines.
-s col_separator
Specifies the column-separator character, which is a blank space by default. To use characters that have special meaning to the operating system (for example, | ; & < >), enclose the character in double quotation marks (“).
-t time_out
Specifies the number of seconds before a command times out. If no time_out value is specified, a command runs indefinitely; the default time-out for logging in to osql is eight seconds.
-m error_level
Customizes the display of error messages. The message number, state, and error level are displayed for errors of the specified severity level or higher. Nothing is displayed for errors of levels lower than the specified level. Use -1 to specify that all headers are returned with messages, even informational messages. If using -1, there must be no space between the parameter and the setting (-m-1, not -m -1).
-I
Sets the QUOTED_IDENTIFIER connection option on.
-L
Lists the locally configured servers and the names of the servers broadcasting on the network.
-?
Displays the syntax summary of osql switches.
-r {0 | 1}
Redirects message output to the screen (stderr). If you don’t specify a parameter, or if you specify 0, only error messages with a severity level 17 or higher are redirected. If you specify 1, all message output (including “print”) is redirected.
-H wksta_name
Is a workstation name. The workstation name is stored in sysprocesses.hostname and is displayed by sp_who. If not specified, the current computer name is assumed.
-P password
Is a user-specified password. If the -P option is not used, osql prompts for a password. If the -P option is used at the end of the command prompt without any password, osql uses the default password (NULL). Passwords are case-sensitive.
The OSQLPASSWORD environment variable allows you to set a default password for the current session. Therefore, you do not have to hard code a password into batch files.
If you do not specify a password with the -P option, osql first checks for the OSQLPASSWORD variable. If no value is set, osql uses the default password, NULL. The following example sets the OSQLPASSWORD variable at a command prompt and then accesses the osql utility:
C:\>SET OSQLPASSWORD=abracadabra
C:\>osql
  
-R
Specifies that the SQL Server ODBC driver use client settings when converting currency, date, and time data to character data.
-S server_name
Specifies the SQL Server installation to which to connect. The server_name is the name of the server computer on the network. This option is required if you are executing osql from a remote computer on the network.
-i input_file
Identifies the file that contains a batch of SQL statements or stored procedures. The less than (<) comparison operator can be used in place of -i.
-o output_file
Identifies the file that receives output from osql. The greater than (>) comparison operator can be used in place of -o.
If input_file is not Unicode and -u is not specified, output_file is stored in OEM format. If input_file is Unicode or -u is specified, output_file is stored in Unicode format.
-u
Specifies that output_file is stored in Unicode format, regardless of the format of the input_file.
-a packet_size
Allows you to request a different-sized packet. The valid values for packet_size are 512 through 65535. The default value osql is the server default. Increased packet size can enhance performance on larger script execution where the amount of SQL statements between GO commands is substantial. Microsoft testing indicates that 8192 is typically the fastest setting for bulk copy operations. A larger packet size can be requested, but osql defaults to the server default if the request cannot be granted.
-b
Specifies that osql exits and returns a DOS ERRORLEVEL value when an error occurs. The value returned to the DOS ERRORLEVEL variable is 1 when the SQL Server error message has a severity of 10 or greater; otherwise the value returned is 0. Microsoft MS-DOS® batch files can test the value of DOS ERRORLEVEL and handle the error appropriately.
-O
Specifies that certain osql features be deactivated to match the behavior of earlier versions of isql. These features are deactivated:
·         EOF batch processing
·         Automatic console width scaling
·         Wide messages
It also sets the default DOS ERRORLEVEL value to -1.
-l time_out
Specifies the number of seconds before an osql login times out. If no time_out value is specified, a command runs indefinitely. The default time-out for login to osql is fifteen seconds.
Remarks
The osql utility is started directly from the operating system with the case-sensitive options listed here. After starting, osql accepts SQL statements and sends them to SQL Server interactively. The results are formatted and displayed on the screen (stdout). Use QUIT or EXIT to exit from osql.
If you do not specify a username when you start osql, SQL Server checks for the environment variables and uses those; for example, osqluser=(user) or osqlserver=(server). If no environment variables are set, the workstation username is used. If you do not specify a server, the name of the workstation is used.
If neither the -U or -P options are used, SQL Server attempts to connect using Windows NT Authentication Mode. Authentication is based on the Microsoft Windows NT® account of the user running osql.
Operating System Commands
Operating system commands can also be executed by starting a line with two exclamation points (!!) followed by the command. The command recall facilities of Windows NT can be used to recall and modify osql statements. The existing query buffer can be cleared by typing RESET.
When running stored procedures, osql prints a blank line between each set of results in a batch. In addition, the “0 rows affected” message does not appear when it doesn’t apply to the statement executed.
Using osql Interactively
To use osql interactively, type the osql command (and any of the options) at a command prompt.
You can read in a file containing a query (such as Stores.qry) for execution by osql by typing a command similar to this:
osql /U alma /P /i stores.qry
  
The file must include a command terminator(s).
You can read in a file containing a query (such as Titles.qry) and direct the results to another file by typing a command similar to this:
osql /U alma /P /i titles.qry /o titles.res
  
When using osql interactively, you can read an operating system file into the command buffer with :r file_name. Do not include a command terminator in the file; enter the terminator interactively after you have finished editing.
Inserting Comments
You can include comments in a Transact-SQL statement submitted to SQL Server by osql. Two types of commenting styles are allowed: -- and /*...*/.
For more information, see Using Comments.
Using EXIT to Return Results in osql
You can use the result of a SELECT statement as the return value from osql. The first column of the first result row is converted to a 4-byte integer (long). MS-DOS passes the low byte to the parent process or operating system error level. Windows NT passes the entire 4-byte integer. The syntax is:
EXIT(query)
For example:
EXIT(SELECT @@ROWCOUNT)
  
EXIT(SELECT 5)
  
You can also include the EXIT parameter as part of a batch file. For example:
osql /Q "EXIT(SELECT COUNT(*) FROM '%1')"
  
The osql utility passes everything between the parentheses ( ) to the server exactly as entered. If a stored system procedure selects a set and returns a value, only the selection is returned. The EXIT( ) statement with nothing between the parentheses executes everything preceding it in the batch and then exits with no return value.
There are four EXIT formats:
  • EXIT
Does not execute the batch; quits immediately and returns no value.
  • EXIT( )
Executes the batch, and then quits and returns no value.
  • EXIT(query)
Executes the batch, including the query, and then quits after returning the results of the query.
  • RAISERROR with a state of 127
  • If RAISERROR is used within an osql script and a state of 127 is raised, osql will quit and return the message ID back to the client. For example:
RAISERROR(50001, 10, 127)
  
This error will cause the osql script to end and the message ID 50001 will be returned to the client.
The return values -1 to -99 are reserved by SQL Server; osql defines these values:
  • -100
Error encountered prior to selecting return value.
  • -101
No rows found when selecting return value.
  • -102
Conversion error when selecting return value.
Displaying money and smallmoney Data Types
osql displays the money and smallmoney data types with two decimal places even though SQL Server stores the value internally with four decimal places. Consider the example:
SELECT CAST(CAST(10.3496 AS money) AS decimal(6, 4))
  
This statement produces a result of 10.3496, which indicates that the value is stored with all decimal places intact.




isql Utility
The isql utility allows you to enter Transact-SQL statements, system procedures, and script files; and uses DB-Library to communicate withSQL Server.
Syntax
isql
    
[-?] |
    [-L] |
    [
        {
            {-U login_id [-P password]}
            | –E        }
        [-S server_name] [-H wksta_name] [-d db_name]
        [-l time_out] [-t time_out] [-h headers]
        [-s col_separator] [-w column_width] [-a packet_size]
        [-e] [-x max_text_size]
        [-c cmd_end] [-q "query"] [-Q "query"]
        [-n] [-m error_level] [-r {0 | 1}]
        [-i input_file] [-o output_file] [-p]
        [-b] [-O]
    ]
Arguments
-?
Displays the syntax summary of isql switches.
-L
Lists the locally configured servers and the names of the servers broadcasting on the network.
-U login_id
Is the user login ID. Login IDs are case-sensitive.
-P password
Is a user-specified password. If the -P option is not used, isql prompts for a password. If the -P option is used at the end of the command prompt without any password, isql uses the default password (NULL).
Security Note  NULL passwords are not recommended.
Passwords are case-sensitive.
The ISQLPASSWORD environment variable allows you to set a default password for the current session. Therefore, you do not have to hard code a password into batch files.
If you do not specify a password with the -P option, isql first checks for the ISQLPASSWORD variable. If no value is set, isql uses the default password, NULL. The following example sets the ISQLPASSWORD variable at the command prompt and then accesses the isql utility:
C:\>SET ISQLPASSWORD=abracadabra
C:\>isql 
Security Note  To mask your password, do not specify the -P option along with the -U option. Instead, after specifying isql along with the -U option and other switches (do not specify -P), press ENTER, and isql will prompt you for a password. This method ensures that your password will be masked when it is entered.
-E
Uses a trusted connection instead of requesting a password.
-S server_name
Specifies the default instance of SQL Server to connect to. isql does not support connecting to a named instance of SQL Server 2000. If no server is specified, isql connects to the default instance of SQL Server on the local computer. This option is required if you are executing isql from a remote computer.
-H wksta_name
Is a workstation name. The workstation name is stored in sysprocesses.hostname and is displayed by sp_who. If not specified, the current computer name is assumed.
-d db_name
Issues a USE db_name statement when isql is started.
-l time_out
Specifies the number of seconds before an isql login times out. If no time_out value is specified, a command runs indefinitely. The default time-out for login to isql is eight seconds.
-t time_out
Specifies the number of seconds before a command times out. If no time_out value is specified, a command runs indefinitely; the default time-out for logging in to isql is eight seconds.
-h headers
Specifies the number of rows to print between column headings. The default is to print headings one time for each set of query results. Use -1 to specify that no headers will be printed. If using -1, there must be no space between the parameter and the setting (-h-1, not -h -1).
-s col_separator
Specifies the column-separator character, which is a blank space by default. To use characters that have special meaning to the operating system (for example, | ; & < >), enclose the character in double quotation marks (").
-w column_width
Allows the user to set the screen width for output. The default is 80 characters. When an output line has reached its maximum screen width, it is broken into multiple lines.
-a packet_size
Allows you to request a different-sized packet. The valid values for packet_size are 512 through 65535. The default value for the Microsoft Windows NT® version of isql is 8192; otherwise, the default value is 512 for Microsoft MS-DOS®, although larger sizes can be requested with that version as well. Increased packet size can enhance performance on larger script execution where the amount of SQL statements between GO commands is substantial. Microsoft testing indicates that 8192 is typically the fastest setting for bulk copy operations. A larger packet size can be requested, but isql defaults to 512 if the request cannot be granted.
-e
Echoes input.
-x max_text_size
Specifies, in bytes, the maximum length of text data to return. Text values longer than max_text_size are truncated. If max_text_size is not specified, text data is truncated at 4096 bytes.
-c cmd_end
Specifies the command terminator. By default, commands are terminated and sent to SQL Server 2000 by entering GO on a line by itself. When you reset the command terminator, do not use Transact-SQL reserved words or characters that have special meaning to the operating system, whether preceded by a backslash or not.
-q "query"
Executes a query when isql starts, but does not exit isql when the query completes. (Note that the query statement should not include GO). If you issue a query from a batch file, you can use %variables. Environment %variables% also work. For example:
SET table = sysobjects
isql /q "Select * from %table%"
Use double quotation marks around the query and single quotation marks around anything embedded in the query.
-Q "query"
Executes a query and immediately exits isql when the query completes. Use double quotation marks around the query and single quotation marks around anything embedded in the query.
-n
Removes numbering and the prompt symbol (>) from input lines.
-m error_level
Customizes the display of error messages. The message number, state, and error level are displayed for errors of the specified severity level or higher. Nothing is displayed for errors of severity levels lower than the specified level. Use -1 to specify that all headers are returned with messages, even informational messages. If -1 is used, there must be no space between the parameter and the setting (-m-1, not -m -1).
-r {0 | 1}
Redirects message output to the screen (stderr). If you do not specify a parameter, or if you specify 0, only error messages with severity 11 or higher are redirected. If you specify 1, all message output (including "print") is redirected.
-i input_file
Identifies the file that contains a batch of SQL statements or stored procedures. The less than (<) comparison operator can be used in place of -i.
-o output_file
Identifies the file that receives output from isql. The greater than (>) comparison operator can be used in place of -o.
-p
Prints performance statistics.
-b
Specifies that isql exits and returns a DOS ERRORLEVEL value when an error occurs. The value returned to the DOS ERRORLEVEL variable is 1 when the SQL Server error message has a severity of 10 or greater; otherwise, the value returned is 0. MS-DOS batch files can test the value of DOS ERRORLEVEL and handle the error appropriately.
-O
Specifies that isql reverts to the behavior of earlier versions. These features are deactivated:
  • EOF batch processing
  • Automatic console width scaling
  • Wide messages
This option also sets the default DOS ERRORLEVEL value to -1.

OSQL vs. ISQL and Query Analyzer


There is a great deal of overlap between ISQL and OSQL. Both support input scripts, output scripts, and most of the same switch arguments. OSQL has no interface. It will only accept a typed command line, or a saved script. In spite of this disadvantage, sometimes ISQL and Query Analyzer cannot accomplish the required task. Working with MSDE is one example. Query Analyzer is not included with the Microsoft Desktop Engine. When developing an application on MSDE, or needing to do MSDE administration, the OSQL utility is the only tool included. Another key difference between ISQL and OSQL is the base library each tool was built on. ISQL is developed on the DB Library, as opposed to OSQL being developed on ODBC. The DB Library works at the SQL 6.5 standard. This difference means ISQL, or any application developed on the DB Library, dose not support some of the new SQL 2000 features. The entire list of unsupported features can found in Books on Line under the title "Connecting Early Version Clients to SQL Server 2000." Some of the main limitations of ISQL include char and varchars defined greater than 255 bytes will be non accessible, big ints will be converted to decimals, sql_variants will be converted to nvarchars, XML results may not be retrieved, and bit fields that are null will be reported as not null with a value of 0. OSQL and Query Analyzer will support all of the SQL 2000 features.
ISQL and OSQL (Object-oriented SQL) are both command-line utilities for entering T-SQL commands for a SQL Server database. ISQL uses an old method of data access known as DB- Library, and is only fully compatible with SQL Server 6.5. It has not been updated with the functionality found in subsequent SQL Server versions. OSQL is an upgrade of ISQL that uses ODBC for data access. ODBC is also quite an old method of data access, but it has been kept up to date and, therefore, the full functionality of T-SQL commands is supported by OSQL.

bcp Utility
The Bulk Copy Program (BCP) is a command-line utility that ships with SQL Server 2000. With BCP, you can import and export large amounts of data in and out of SQL Server 2000 databases. Having BCP in your arsenal of DBA tools will add to your skill set and make you a better-rounded DBA. Let's begin by showing you the syntax of BCP as well as how to effectively use the tool.
Syntax
bcp {[[database_name.][owner].]{table_name | view_name} | "query"}
    {in | out | queryout | format} data_file
    [-m max_errors] [-f format_file] [-e err_file]
    [-F first_row] [-L last_row] [-b batch_size]
    [-n] [-c] [-w] [-N] [-V (60 | 65 | 70)] [-6]
    [-q] [-C code_page] [-t field_term] [-r row_term]
    [-i input_file] [-o output_file] [-a packet_size]
    [-S server_name[\instance_name]] [-U login_id] [-P password]
    [-T] [-v] [-R] [-k] [-E] [-h "hint [,...n]"]
database_name
Is the name of the database in which the specified table or view resides. If not specified, this is the default database for the user.
Owner
Is the name of the owner of the table or view. owner is optional if the user performing the bulk copy operation owns the specified table or view. If owner is not specified and the user performing the bulk copy operation does not own the specified table or view, Microsoft® SQL Server™ 2000 returns an error message, and the bulk copy operation is canceled.
table_name
Is the name of the destination table when copying data into SQL Server (in), and the source table when copying data from SQL Server (out).
view_name
Is the name of the destination view when copying data into SQL Server (in), and the source view when copying data from SQL Server (out). Only views in which all columns refer to the same table can be used as destination views. For more information on the restrictions for copying data into views, see INSERT.
Query
Is a Transact-SQL query that returns a result set. If the query returns multiple result sets, such as a SELECT statement that specifies a COMPUTE clause, only the first result set is copied to the data file; subsequent result sets are ignored. Use double quotation marks around the query and single quotation marks around anything embedded in the query. queryout must also be specified when bulk copying data from a query.
in | out | queryout | format
Specifies the direction of the bulk copy. in copies from a file into the database table or view. out copies from the database table or view to a file. queryout must be specified only when bulk copying data from a query. format creates a format file based on the option specified (-n, -c, -w, -6, or -N) and the table or view delimiters. If format is used, the -f option must be specified as well.
Note  The bcp utility included with Microsoft SQL Server 6.5 does not support bulk copying into tables that contain the sql_variant or bigint data types.
data_file
Is the full path of the data file used when bulk copying a table or view to or from a disk. When bulk copying data into SQL Server, the data file contains the data to be copied into the specified table or view. When bulk copying data from SQL Server, the data file contains the data copied from the table or view. The path can have from 1 through 255 characters.
-m max_errors
Specifies the maximum number of syntax errors and compilation errors that can occur before the bulk copy operation is canceled. Each row that cannot be copied by bcp is ignored and counted as one error. If this option is not included, the default is 10.
Note  The max_errors option does not apply to constraint checks (or to converting money and bigint data types).
-f format_file
Specifies the full path of the format file that contains stored responses from a previous use of bcp on the same table or view. Use this option when using a format file created with the format option to bulk copy data in or out. Creation of the format file is optional. After prompting you with format questions, bcp prompts whether to save the answers in a format file. The default file name is Bcp.fmt. bcp can refer to a format file when bulk copying data; therefore, reentering previous format responses interactively is not necessary. If this option is not used and -n, -c, -w, -6, or -N is not specified, bcp prompts for format information.
-e err_file
Specifies the full path of an error file used to store any rows bcp is unable to transfer from the file to the database. Error messages from bcp go to the user's workstation. If this option is not used, an error file is not created.
-F first_row
Specifies the number of the first row to bulk copy. The default is 1, indicating the first row in the specified data file.
-L last_row
Specifies the number of the last row to bulk copy. The default is 0, indicating the last row in the specified data file.
-b batch_size
Specifies the number of rows per batch of data copied. Each batch is copied to the server as one transaction. SQL Server commits or rolls back, in the case of failure, the transaction for every batch. By default, all data in the specified data file is copied in one batch. Do not use in conjunction with the -h "ROWS_PER_BATCH = bb" option.
-n
Performs the bulk copy operation using the native (database) data types of the data. This option does not prompt for each field; it uses the native values.
-c
Performs the bulk copy operation using a character data type. This option does not prompt for each field; it uses char as the storage type, no prefixes, \t (tab character) as the field separator, and \n (newline character) as the row terminator.
-w
Performs the bulk copy operation using Unicode characters. This option does not prompt for each field; it uses nchar as the storage type, no prefixes, \t (tab character) as the field separator, and \n (newline character) as the row terminator. Cannot be used with SQL Server version 6.5 or earlier.
-N
Performs the bulk copy operation using the native (database) data types of the data for noncharacter data, and Unicode characters for character data. This option offers a higher performance alternative to the -w option, and is intended for transferring data from one SQL Server to another using a data file. It does not prompt for each field. Use this option when you are transferring data that contains ANSI extended characters and you want to take advantage of the performance of native mode. -N cannot be used with SQL Server 6.5 or earlier.
-V (60 | 65 | 70)
Performs the bulk copy operation using data types from an earlier version of SQL Server. Use this option in conjunction with character (-c) or native (-n) format. This option does not prompt for each field; it uses the default values. For example, to bulk copy date formats supported by the bcp utility provided with SQL Server 6.5 (but no longer supported by ODBC) into SQL Server 2000, use the -V 65 parameter.
Important  When bulk copying data from SQL Server into a data file, the bcp utility does not generate SQL Server 6.0 or SQL Server 6.5 date formats for any datetime or smalldatetime data, even if -V is specified. Dates are always written in ODBC format. Additionally, null values in bit columns are written as the value 0 because SQL Server versions 6.5 and earlier do not support nullable bit data.
-6
Performs the bulk copy operation using SQL Server 6.0 or SQL Server 6.5 data types. Supported for backward compatibility only. Use the -V option instead.
-q
Executes the SET QUOTED_IDENTIFIERS ON statement in the connection between the bcp utility and an instance of SQL Server. Use this option to specify a database, owner, table, or view name that contains a space or a quotation mark. Enclose the entire three-part table or view name in double quotation marks (" ").
-C code_page
Supported for backward compatibility only. Instead, specify a collation name for each column in the format file or in interactive bcp.
Specifies the code page of the data in the data file. code_page is relevant only if the data contains char, varchar, or text columns with character values greater than 127 or less than 32.
Code page value
Description
ACP
ANSI/Microsoft Windows® (ISO 1252).
OEM
Default code page used by the client. This is the default code page used by bcp if -C is not specified.
RAW
No conversion from one code page to another occurs. This is the fastest option because no conversion occurs.
<value>
Specific code page number, for example, 850.


-t field_term
Specifies the field terminator. The default is \t (tab character). Use this parameter to override the default field terminator.
-r row_term
Specifies the row terminator. The default is \n (newline character). Use this parameter to override the default row terminator.
-i input_file
Specifies the name of a response file, containing the responses to the command prompt questions for each field when performing a bulk copy using interactive mode (-n, -c, -w, -6, or -N not specified).
-o output_file
Specifies the name of a file that receives output from bcp redirected from the command prompt.
-a packet_size
Specifies the number of bytes, per network packet, sent to and from the server. A server configuration option can be set by using SQL Server Enterprise Manager (or the sp_configure system stored procedure). However, the server configuration option can be overridden on an individual basis by using this option. packet_size can be from 4096 to 65535 bytes; the default is 4096.
Increased packet size can enhance performance of bulk copy operations. If a larger packet is requested but cannot be granted, the default is used. The performance statistics generated by bcp show the packet size used.
-S server_name[\instance_name]
Specifies the instance of SQL Server to connect to. Specify server_name to connect to the default instance of SQL Server on that server. Specify server_name\instance_name to connect to a named instance of SQL Server 2000 on that server. If no server is specified, bcp connects to the default instance of SQL Server on the local computer. This option is required when executing bcp from a remote computer on the network.
-U login_id
Specifies the login ID used to connect to SQL Server.
Security Note  When possible, use the -T option (trusted connection).
-P password
Specifies the password for the login ID. If this option is not used, bcp prompts for a password. If this option is used at the end of the command prompt without a password, bcp uses the default password (NULL).
Security Note  NULL passwords are not recommended.
Security Note  To mask your password, do not specify the -P option along with the -U option. Instead, after specifying bcp along with the -U option and other switches (do not specify -P), press ENTER, and bcp will prompt you for a password. This method ensures that your password will be masked when it is entered.
-T
Specifies that bcp connects to SQL Server with a trusted connection, using the security credentials of the network user. login_id and password are not required.
-v
Reports the bcp utility version number and copyright.
-R
Specifies that currency, date, and time data is bulk copied into SQL Server using the regional format defined for the locale setting of the client computer. By default, regional settings are ignored.
-k
Specifies that empty columns should retain a null value during the bulk copy operation, rather than have any default values for the columns inserted.
-E
Specifies that the values for an identity column are present in the file being imported. If -E is not given, the identity values for this column in the data file being imported are ignored, and SQL Server 2000 automatically assigns unique values based on the seed and increment values specified during table creation. If the data file does not contain values for the identity column in the table or view, use a format file to specify that the identity column in the table or view should be skipped when importing data; SQL Server 2000 automatically assigns unique values for the column. For more information, see DBCC CHECKIDENT.
-h "hint [,...n]"
Specifies the hint(s) to be used during a bulk copy of data into a table or view. This option cannot be used when bulk copying data into SQL Server 6.x or earlier.
Hint
Description
ORDER (column [ASC | DESC] [,...n])
Sort order of the data in the data file. Bulk copy performance is improved if the data being loaded is sorted according to the clustered index on the table. If the data file is sorted in a different order, or there is no clustered index on the table, the ORDER hint is ignored. The names of the columns supplied must be valid columns in the destination table. By default, bcp assumes the data file is unordered.
ROWS_PER_BATCH = bb
Number of rows of data per batch (as bb). Used when -b is not specified, resulting in the entire data file being sent to the server as a single transaction. The server optimizes the bulk load according to the value bb. By default, ROWS_PER_BATCH is unknown.
KILOBYTES_PER_BATCH = cc
Approximate number of kilobytes (KB) of data per batch (as cc). By default, KILOBYTES_PER_BATCH is unknown.
TABLOCK
A table-level lock is acquired for the duration of the bulk copy operation. This hint significantly improves performance because holding a lock only for the duration of the bulk copy operation reduces lock contention on the table. A table can be loaded concurrently by multiple clients if the table has no indexes and TABLOCK is specified. By default, locking behavior is determined by the table option table lock on bulk load.
CHECK_CONSTRAINTS
Any constraints on the destination table are checked during the bulk copy operation. By default, constraints are ignored. Note that the max_errors option does not apply to constraint checking.
FIRE_TRIGGERS
Specified with the in argument, any insert triggers defined on the destination table will execute during the bulk copy operation. If FIRE_TRIGGERS is not specified, no insert triggers will execute. FIRE_TRIGGERS is ignored for the out, queryout, and format arguments.

No comments:

Post a Comment