devxlogo

Sql Server

The sp rename SQL Stored Procedure

You can not use the ALTER TABLE statement in SQL Server to rename a column in a table. You can however, use the sp_rename stored procedure if you do not

Enumerating all SQL Servers

It is quite easy to enumerate (list) all the possible SQL servers to which you want to connect. Here is a small example: using System;using System.Data;using System.Text;using System.Windows.Forms;namespace SqlServerEnumeratorCS{ public

The sp_MSforeachdb Stored Procedure

The sp_MSforeachdb stored procedure helps you to do repetitive actions against all or some of the SQL Server instance databases. For example, this query: EXEC sp_MSforeachdb ‘USE [?]; EXEC sp_spaceused’

Renaming an SQL Server Database

You can use the following query to rename an SQL Database: USE masterGOALTER DATABASE YOURDATABASENAME SET SINGLE_USER WITH ROLLBACK IMMEDIATEGOEXEC master..sp_renamedb ‘YOURDATABASENAME’,’YOUR_NEW_DATABASE_NAME’GOALTER DATABASE YOUR_NEW_DATABASE_NAME SET MULTI_USER GO The only problem,

Importing Data from Excel into SQL Server

A very quick way to import data from Excel into SQL Server through code is to execute the following query: SELECT * FROM OPENROWSET(‘Microsoft.ACE.OLEDB.12.0′,’Excel 12.0;Database=C:ExcelFileToImport.xlsx’, [SheetWhereDataIsLocated$]) This is known as

Filling a Field with Data

Question: How can I fill a numeric field with a sequence of numbers using SQL? For example, I want a field named NUMBER to contain the numbers 1 for the

Starting NT Services for SQL Databases

The Windows NT installation process for SQL servers from Oracle, Microsoft, IBM, Sybase, and Informix installs NT services. Not all products include a graphical tool that enables you to start