Knebel Home
{ SQL Server }
ADO.NET: Connection string to localhost
This is just a standard code snipplet to eliminate re-typing a conn string to my box. Assumes your Windows login has all rights to the SQL Server via NT/Token Authentication. (Written for .Net)
Create Index
Here's the syntax for creating an MSSQL Index on an existing field:
Create Linked SQL Servers
Here's how you can link SQL Server databases across servers:
Creating table with an insert statement
insert into, select into commands for sql
Date Formatting (using Convert)
Date Conversion Functions. Paste the following code into Query Analyzer.
Delete Statement with Joins & Top function!
Here is one of those hairy delete SQL statements. Here we are deleting from TABLE1 where pKey does NOT match Field1 in TABLE2. We want to delete in chunks, so the top option is used.
Disable (enable) triggers
Disabling triggers on-the-fly example:
Example of an Update Using a Join Statement
Here is an example of how you can update records from seperate tables using a join statement.
Get row count for all tables
Get row count for all tables in a database
Get row count for all tables
Get row count for all tables in a database
Rebuild Table Indexes (Cursor Loop)
Rebuild all indexes by looping through tables using a cursor. This is a good example of how you can use CURSORs in MS SQL Server.
Restoring DTS Packages
A simple way to transfer your DTS packages from one server to another is as follows: Using Restore Databse (old MSDB on new server): 1. Make backup of source MSDB database. 2. Restore that backup as a new database on the destinati...
Transferring SQL Server Jobs
A simple way to transfer your SQL Jobs from one server to another is as follows: 1. Make backup of source MSDB database. 2. Restore that backup as a new database on the destination server. In this example, the database is restored as DTS_Recover...
Truncate a SQL Server Database Log
Have you ever run out of space while running a big transaction set? Here's how to free up your log file space. NOTE: It is highly recommended to perform a backup of your database immediately BEFORE AND AFTER truncating the log files so you ...
XML: Querying MS Sql Server Virtual Directories with XML Integration
The two main components for this very basic xml document from Microsoft SQL Server are: - SQL Statement (querystring variable "sql") - Root element (querystring variable "root") Note: You will first need to use the "Configure SQL XML Support...