| Function to strip HTML from a string
Below is a function that can be used to strip HTML from a string. It works by looping through the string until it meets an opening HTML tag, and ignores....
|
SQL Server |
Get a list of views in the database
To get a list of views within the database run the following query.
select * from sysobjects where....
|
SQL Server |
| Getting a list of filenames into a table
The following short TSQL will read files from disk into a table.
The example below will read all the files from the root of the C directory into a local....
|
SQL Server |
A query to retrieve a list of Columns in a table
To return a list of columns and their data types for a table use the following query.
Replace 'MyTableName' with the name of the table you wish to....
|
SQL Server |
| Function to remove letters from a string
Imagine a scenario where you have a datafield containing a series of identifiers with diferent prefixes that are alpha characters but are different lengths and....
|
SQL Server |
xp_cmdshell not enabled
If xp_cmdshell is not enabled, and you have sufficient rights it can be enabled with the following script.
sp_configure 'show advanced options',....
|
SQL Server |
| Finding the structure of a table in a query
All the information about each table in the database is held within the database itself, and the following query can be used to investigate, or extract the....
|
SQL Server |
Finding the size of table within a database
To find out how much physical disk space a table takes up execute the following stored procedure.
EXEC sp_spaceused N'[TableName]'
This will return the....
|
SQL Server |
Finding the name of the server
To discover the network name of the server that SQL is physically located on, the extended stored procedure xp_getnetname can be used.
On its own it simply....
|
SQL Server |
Getting a list of databases with sp_databases
The stored procedure sp_databases will return the list of the databases on the current SQL server.
Running the sp_databases procedure on its own will return....
|
SQL Server |
| Selecting random records
A quick way of selecting a batch of random records from a SQL table is to include the NEWID() function in the WHERE clause. This function generates Windows....
|
SQL Server |
DELETE vs TRUNCATE when removing rows from a table.
There are two methods to do this either using a TRUNCATE or DELETE command.
Both have their advantages and disadvantages
TRUNCATE TABLE [TableName]
This....
|
SQL Server |
| Write a text file directly from a query
Without using export functions or DTS to write text or CSV files directly from a stored procedure, add the following into your database. It uses the....
|
SQL Server |
| Script to assign table rights to public group
When granting access to tables in SQL Server, it is standard practice not to
simply make the login 'dbo' or 'sa', to save the bother of assigning rights....
|
SQL Server |
| Script to shrink all user SQL databases
To truncate transaction logs and free wasted space on a SQL server, the following script will shrink all the user databases on a single server. This has the....
|
SQL Server |
|   |
| 1 2
17 Results found.
|