Posts tagged Columns

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 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 [...]

List of primary key fields within a database

0
The query below lists the Table Name, Column Name, and Column ID for all Primary Key columns within a database SELECT  t.name AS TableName, c.name AS ColumnName, c.colid AS ColumnID FROM      sysindexes i   INNER JOIN sysobjects t       ON i.id = t.id   INNER JOIN sysindexkeys k     ON i.indid = [...]

List of table columns, with data types

2
The Transact-SQL query below, returns the table name, column name, data type, and maximum length. This is useful when producing database documentation SELECT       schema_name(O.schema_id) + '.' + O.name AS TableName,       C.name AS ColumnName,       T.name AS Type,       C.max_length AS [...]
Go to Top