background preloader

SQL Server

Facebook Twitter

Use the sqlcmd Utility. A. Running a script by using sqlcmd Start Notepad, and type the following Transact-SQL statements: USE AdventureWorks2012; SELECT TOP (3) BusinessEntityID, FirstName, LastName FROM Person.Person; Create a folder named MyFolder and then save the script as the file MyScript.sql in the folder C:\MyFolder. Sqlcmd -i C:\MyFolder\MyScript.sql -o C:\MyFolder\MyOutput.txt When you view the contents of MyOutput.txt in Notepad, you will see the following: Changed database context to 'AdventureWorks2012'. BusinessEntityID FirstName LastName 1 Syed Abbas 2 Catherine Abel 3 Kim Abercrombie (3 rows affected) B. In the following example, sqlcmd is used to connect to a server that has a blocking problem by using the dedicated administrator connection (DAC).

C:\>sqlcmd -S ServerName -A 1> SELECT blocked FROM sys.dm_exec_requests WHERE blocked <> 0; Here is the result set. spid blocked (1 rows affected) Use sqlcmd to end the blocking process. C. IF OBJECT_ID ( ' dbo.ContactEmailAddress, 'P' ) IS NOT NULL SELECT EmailAddress. Asp.net - SQL Server 2005 - How often should you rebuild Indexes. Local SQL Server 2008 ColdFusion Datasource | Matt Gifford aka coldfumonkeh. This morning I finished installing SQL Server 2008 on my local machine for development. Having set up the database, I hit a small issue when trying to add the database as a datasource within the ColdFusion administrator, receiving the following error: Connection verification failed for data source: romixrDB java.sql.SQLNonTransientConnectionException: [Macromedia][SQLServer JDBC Driver]Error establishing socket to host and port: 127.0.0.1:1433.

Reason: Connection refused: connect The root cause was that: java.sql.SQLNonTransientConnectionException: [Macromedia][SQLServer JDBC Driver]Error establishing socket to host and port: 127.0.0.1:1433. Reason: Connection refused: connect You can see a connection issue with the datasource, with a failure to connect on the socket using the localhost (127.0.0.1) and port number (1433). By default, SQL Server 2008 doesn’t have the port number enabled. Change the ‘Enabled’ option to YES under the ‘Protocol’ tab. ALTER TABLE (Transact-SQL) Database_name Is the name of the database in which the table was created. schema_name Is the name of the schema to which the table belongs. table_name Is the name of the table to be altered.

If the table is not in the current database or is not contained by the schema owned by the current user, the database and schema must be explicitly specified. Specifies that the named column is to be changed or altered. The modified column cannot be any one of the following: A column with a timestamp data type. The data type of columns included in an index cannot be changed unless the column is a varchar, nvarchar, or varbinary data type, and the new size is equal to or larger than the old size. A columns included in a primary key constraint, cannot be changed from NOT NULL to NULL. column_name Is the name of the column to be altered, added, or dropped. column_name can be a maximum of 128 characters. . [ type_schema_name. ] type_name A SQL Server system data type. Precision scale max xml_schema_collection. Bcp Utility. Data_file Is the full path of the data file.

When data is bulk imported into SQL Server, the data file contains the data to be copied into the specified table or view. When data is bulk exported from SQL Server, the data file contains the data copied from the table or view. The path can have from 1 through 255 characters. The data file can contain a maximum of 263 - 1 rows. database_name Is the name of the database in which the specified table or view resides. You can also explicitly specify the database name with d-. in data_file | outdata_file | queryoutdata_file | format nul Specifies the direction of the bulk copy, as follows: in copies from a file into the database table or view. Owner Is the name of the owner of the table or view. owner is optional if the user performing the operation owns the specified table or view. " query " Is a Transact-SQL query that returns a result set.

Table_name view_name -a packet_size Increased packet size can enhance performance of bulk-copy operations. -c -k.