sp_columns (Transact-SQL)sp_columns (Transact-SQL)
適用対象:Applies to: SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
Azure SQL データベースAzure SQL Database
Azure SQL データベースAzure SQL Database
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Parallel Data WarehouseParallel Data Warehouse
Parallel Data WarehouseParallel Data Warehouse
SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
Azure SQL データベースAzure SQL Database
Azure SQL データベースAzure SQL Database
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Parallel Data WarehouseParallel Data Warehouse
Parallel Data WarehouseParallel Data Warehouse
現在の環境でクエリを実行できる、指定されたオブジェクトの列情報を返します。Returns column information for the specified objects that can be queried in the current environment.
Transact-SQL 構文表記規則
Transact-SQL Syntax Conventions
構文Syntax
-- Syntax for SQL Server, Azure SQL Database, Azure Synapse Analytics, Parallel Data Warehouse
sp_columns [ @table_name = ] object
[ , [ @table_owner = ] owner ]
[ , [ @table_qualifier = ] qualifier ]
[ , [ @column_name = ] column ]
[ , [ @ODBCVer = ] ODBCVer ]
引数Arguments
[ \@table_name = ] object
カタログ情報を返すために使用するオブジェクトの名前を指定します。[ \@table_name = ] object
Is the name of the object that is used to return catalog information. オブジェクト には、テーブル、ビュー、またはテーブル値関数などの列を持つその他のオブジェクトを指定できます。object can be a table, view, or other object that has columns such as table-valued functions. オブジェクト は nvarchar (384),、既定値はありません。object is nvarchar(384), with no default. ワイルドカードパターンマッチングがサポートされています。Wildcard pattern matching is supported.
[ \@table_owner = ] owner
カタログ情報を返すために使用されるオブジェクトの所有者を示します。[ \@table_owner = ] owner
Is the object owner of the object that is used to return catalog information. owner は nvarchar (384),、既定値は NULL です。owner is nvarchar(384), with a default of NULL. ワイルドカードパターンマッチングがサポートされています。Wildcard pattern matching is supported. Owner が指定されていない場合、基になる DBMS の既定のオブジェクト可視性ルールが適用されます。If owner is not specified, the default object visibility rules of the underlying DBMS apply.
指定した名前のオブジェクトを現在のユーザーが所有している場合は、そのオブジェクトの列が返されます。If the current user owns an object with the specified name, the columns of that object are returned. Owner が指定されておらず、現在のユーザーが指定された オブジェクト を持つオブジェクトを所有していない場合、 sp_columns は、データベース所有者が所有する、指定された オブジェクト を持つオブジェクトを検索します。If owner is not specified and the current user does not own an object with the specified object, sp_columns looks for an object with the specified object owned by the database owner. 存在する場合は、そのオブジェクトの列が返されます。If one exists, that object's columns are returned.
[ \@table_qualifier = ] qualifier
オブジェクト修飾子の名前を指定します。[ \@table_qualifier = ] qualifier
Is the name of the object qualifier. 修飾子 は sysname,、既定値は NULL です。qualifier is sysname, with a default of NULL. さまざまな DBMS 製品では、3つの要素で構成するオブジェクト (修飾子) がサポート しています。所有者。名前)。Various DBMS products support three-part naming for objects (qualifier.owner.name). では SQL ServerSQL Server 、この列はデータベース名を表します。In SQL ServerSQL Server, this column represents the database name. 一部の製品では、オブジェクトのデータベース環境のサーバー名を表します。In some products, it represents the server name of the object's database environment.
[ \@column_name = ] column
は1つの列であり、カタログ情報の列が1つだけ必要な場合に使用します。[ \@column_name = ] column
Is a single column and is used when only one column of catalog information is wanted. 列 は nvarchar (384),、既定値は NULL です。column is nvarchar(384), with a default of NULL. 列 が指定されていない場合は、すべての列が返されます。If column is not specified, all columns are returned. では SQL ServerSQL Server 、 列 は syscolumns テーブルに示されている列名を表します。In SQL ServerSQL Server, column represents the column name as listed in the syscolumns table. ワイルドカードパターンマッチングがサポートされています。Wildcard pattern matching is supported. 相互運用性を最大にするために、ゲートウェイクライアントでは、SQL-92 標準のパターン照合 (% と _ ワイルドカード文字) のみを想定する必要があります。For maximum interoperability, the gateway client should assume only SQL-92 standard pattern matching (the % and _ wildcard characters).
[ \@ODBCVer = ] ODBCVer
使用されている ODBC のバージョンを示します。[ \@ODBCVer = ] ODBCVer
Is the version of ODBC that is being used. Odbcver は int,、既定値は2です。ODBCVer is int, with a default of 2. これは、ODBC バージョン2を示します。This indicates ODBC Version 2. 有効な値は2または3です。Valid values are 2 or 3. バージョン2とバージョン3の動作の違いについては、ODBC Sqlcolumns の仕様を参照してください。For the behavior differences between versions 2 and 3, see the ODBC SQLColumns specification.
リターン コードの値Return Code Values
なしNone
結果セットResult Sets
Sp_columns カタログストアドプロシージャは、ODBC の sqlcolumns に相当します。The sp_columns catalog stored procedure is equivalent to SQLColumns in ODBC. 返される結果は、 TABLE_QUALIFIER、 TABLE_OWNER、および TABLE_NAME 順に並べ替えられます。The results returned are ordered by TABLE_QUALIFIER, TABLE_OWNER, and TABLE_NAME.
列名Column name | データ型Data type | 説明Description |
---|---|---|
TABLE_QUALIFIERTABLE_QUALIFIER | sysnamesysname | オブジェクト修飾子の名前です。Object qualifier name. このフィールドは NULL にすることができます。This field can be NULL. |
TABLE_OWNERTABLE_OWNER | sysnamesysname | オブジェクト所有者の名前。Object owner name. このフィールドは常に値を返します。This field always returns a value. |
TABLE_NAMETABLE_NAME | sysnamesysname | オブジェクト名Object name. このフィールドは常に値を返します。This field always returns a value. |
COLUMN_NAMECOLUMN_NAME | sysnamesysname | 返される TABLE_NAME の各列の列名。Column name, for each column of the TABLE_NAME returned. このフィールドは常に値を返します。This field always returns a value. |
DATA_TYPEDATA_TYPE | smallintsmallint | ODBC データ型の整数コードです。Integer code for ODBC data type. ODBC のデータ型にマップできないデータ型の場合は、NULL になります。If this is a data type that cannot be mapped to an ODBC type, it is NULL. ネイティブデータ型の名前が TYPE_NAME 列に返されます。The native data type name is returned in the TYPE_NAME column. |
TYPE_NAMETYPE_NAME | sysnamesysname | データ型を表す文字列。String representing a data type. 基になる DBMS は、このデータ型の名前を提示します。The underlying DBMS presents this data type name. |
PRECISIONPRECISION | intint | 有効桁数。Number of significant digits. 有効桁数 列の戻り値は、10進数値です。The return value for the PRECISION column is in base 10. |
LENGTHLENGTH | intint | データの転送サイズ。1Transfer size of the data.1 |
段階SCALE | smallintsmallint | 小数点の右側の桁数。Number of digits to the right of the decimal point. |
RADIXRADIX | smallintsmallint | 数値データ型のベース。Base for numeric data types. |
NULLABLENULLABLE | smallintsmallint | Null 値の許容属性を指定します。Specifies nullability. 1 = NULL 値を許容します。1 = NULL is possible. 0 = NULL 値を許容しません。0 = NOT NULL. |
備考REMARKS | varchar (254)varchar(254) | このフィールドは常に NULL を返します。This field always returns NULL. |
COLUMN_DEFCOLUMN_DEF | nvarchar (4000)nvarchar(4000) | 列の既定値です。Default value of the column. |
SQL_DATA_TYPESQL_DATA_TYPE | smallintsmallint | 記述子の TYPE フィールドでの SQL データ型の値です。Value of the SQL data type as it appears in the TYPE field of the descriptor. この列は、 datetime および SQL-92 interval データ型を除き、 DATA_TYPE 列と同じです。This column is the same as the DATA_TYPE column, except for the datetime and SQL-92 interval data types. この列は常に値が返されます。This column always returns a value. |
SQL_DATETIME_SUBSQL_DATETIME_SUB | smallintsmallint | Datetime および SQL-92 interval データ型のサブタイプコード。Subtype code for datetime and SQL-92 interval data types. 他のデータ型の場合、この列は NULL を返します。For other data types, this column returns NULL. |
CHAR_OCTET_LENGTHCHAR_OCTET_LENGTH | intint | 文字型または整数型の列の最大長 (バイト単位)。Maximum length in bytes of a character or integer data type column. 他のすべてのデータ型については、この列は NULL を返します。For all other data types, this column returns NULL. |
ORDINAL_POSITIONORDINAL_POSITION | intint | オブジェクト内の列の序数位置。Ordinal position of the column in the object. オブジェクトの最初の列は1です。The first column in the object is 1. この列は常に値が返されます。This column always returns a value. |
IS_NULLABLEIS_NULLABLE | varchar (254)varchar(254) | オブジェクト内の列の NULL 値の許容属性です。Nullability of the column in the object. ISO ルールの後に、null 値の許容属性が決定されます。ISO rules are followed to determine nullability. ISO SQL に準拠している DBMS では、空の文字列を返すことはできません。An ISO SQL-compliant DBMS cannot return an empty string. YES = 列に NULL を含むことができます。YES = Column can include NULLS. NO = 列に NULL を含めることはできません。NO = Column cannot include NULLS. Null 値許容属性が不明の場合、この列は長さ0の文字列を返します。This column returns a zero-length string if nullability is unknown. この列に返される値は、 Null 許容 列に対して返される値とは異なります。The value returned for this column is different from the value returned for the NULLABLE column. |
SS_DATA_TYPESS_DATA_TYPE | tinyinttinyint | SQL ServerSQL Server 拡張ストアドプロシージャによって使用されるデータ型。data type used by extended stored procedures. 詳細については、「データ型 (Transact-SQL)」を参照してください。For more information, see Data Types (Transact-SQL). |
1 詳細については、Microsoft ODBC のドキュメントを参照してください。1 For more information, see the Microsoft ODBC documentation.
アクセス許可Permissions
スキーマに対する SELECT および VIEW DEFINITION 権限が必要です。Requires SELECT and VIEW DEFINITION permissions on the schema.
コメントRemarks
sp_columns は、区切られた識別子の要件に従います。sp_columns follows the requirements for delimited identifiers. 詳細については、「データベース識別子」を参照してください。For more information, see Database Identifiers.
例Examples
次の例では、指定されたテーブルの列情報を返します。The following example returns column information for a specified table.
USE AdventureWorks2012;
GO
EXEC sp_columns @table_name = N'Department',
@table_owner = N'HumanResources';
例: Azure Synapse AnalyticsAzure Synapse Analytics、Parallel Data WarehouseParallel Data WarehouseExamples: Azure Synapse AnalyticsAzure Synapse Analytics and Parallel Data WarehouseParallel Data Warehouse
次の例では、指定されたテーブルの列情報を返します。The following example returns column information for a specified table.
-- Uses AdventureWorks
EXEC sp_columns @table_name = N'DimEmployee',
@table_owner = N'dbo';
参照See Also
sp_tables (Transact-sql) sp_tables (Transact-SQL)
Transact-sql)(のカタログストアドプロシージャ Catalog Stored Procedures (Transact-SQL)
システム ストアド プロシージャ (Transact-SQL)System Stored Procedures (Transact-SQL)