Posts tagged Tables

Table information – column lengths, counts and unique counts

1
Hi. The Transact-SQL script below returns the following information: ID – Just an identity column used within the script SchemaName – The name of the schema TableName – Obviously, the name of the table ColumnName Type – The data type of the column Length – The maximum number of bytes used by the [...]

Do you want to execute a Stored Procedure as part of a SELECT statement??

0
I was on a training course at the end of September, and came across a way to execute a simple stored procedure as part of a select statement using an Inline Table Valued Function. You (like me) have probably tried to run the following statement expecting to get results from a stored procedure: USE [...]

List of tables and indexes, with associated File Group

0
The script below (written using SQL Server 2005), returns a list of all tables (along with the schema name), and indexes (where they exist), and the name of the associated file group. This will useful to find out which objects have been assigned to the wrong file group. I have a database with over [...]

Search all table columns for specific text

0
I needed to find out which columns within all tables in the database, contained a specific string of text. I therefore wrote the script below to do exactly that CREATE TABLE TempTableColumnResults ( TableName VARCHAR(100),   ColumnName VARCHAR(100) ) DECLARE @TableName VARCHAR(100) DECLARE [...]

Count the number of records in each table within a database

0
The Transact-SQL script below (written for SQL Server 2000, but also works with 2005), returns a list of tables and a count of the number of records within each table. USE [database name] GO DECLARE @name VARCHAR(500) DECLARE @sql VARCHAR(1000) CREATE TABLE #TableRecordCount ( TableName [...]

Finding table column names with a specific word

0
The code below can be used to find all tables that contain columns that have “ADDRESS” in the name. It can easily be modified to search for table column names with any specific word. SELECT     CASE O.xtype WHEN 'U' THEN 'Table' WHEN 'V' THEN 'View' END AS Type,     O.name AS TableName,     [...]

Count of values within every field in a table

0
The Transact-SQL script below (written for SQL Server 2005), returns a list of the values and a count for each and every field within a table. You just need to change the schema name and table name, and specify a limit (if needed) for the number of values returned for each field. For [...]

Generate a list of tables for all databases on a server

0
The following Transact-SQL can be used to generate a list of tables for all the databases on a server: USE master GO DECLARE @dbID INT DECLARE @name VARCHAR(500) DECLARE @sql VARCHAR(1000)   CREATE TABLE #databasetables ( DatabaseID INT,   DatabaseName VARCHAR(100),   TableID INT,   TableName [...]
Go to Top