Официальный сайт студ.городка НГТУ
Программирование и БД » [SQL] Селект названия полей таблицы. Как? 

#1  09.11.11 23:50

[SQL] Селект названия полей таблицы. Как?

Сабж.

Offline

#2  10.11.11 09:47

Igo
Профиль

Re: [SQL] Селект названия полей таблицы. Как?

Syntax:
SHOW [FULL] COLUMNS {FROM | IN} tbl_name [{FROM | IN} db_name]
    [LIKE 'pattern' | WHERE expr]

SHOW COLUMNS displays information about the columns in a given table.
It also works for views. The LIKE clause, if present, indicates which
column names to match. The WHERE clause can be given to select rows
using more general conditions, as discussed in
http://dev.mysql.com/doc/refman/5.1/en/ … -show.html.

mysql> SHOW COLUMNS FROM City;
+------------+----------+------+-----+---------+----------------+
| Field      | Type     | Null | Key | Default | Extra          |
+------------+----------+------+-----+---------+----------------+
| Id         | int(11)  | NO   | PRI | NULL    | auto_increment |
| Name       | char(35) | NO   |     |         |                |
| Country    | char(3)  | NO   | UNI |         |                |
| District   | char(20) | YES  | MUL |         |                |
| Population | int(11)  | NO   |     | 0       |                |
+------------+----------+------+-----+---------+----------------+
5 rows in set (0.00 sec)

If the data types differ from what you expect them to be based on a
CREATE TABLE statement, note that MySQL sometimes changes data types
when you create or alter a table. The conditions under which this
occurs are described in
http://dev.mysql.com/doc/refman/5.1/en/ … anges.html.

The FULL keyword causes the output to include the column collation and
comments, as well as the privileges you have for each column.

You can use db_name.tbl_name as an alternative to the tbl_name FROM
db_name syntax. In other words, these two statements are equivalent:

mysql> SHOW COLUMNS FROM mytable FROM mydb;
mysql> SHOW COLUMNS FROM mydb.mytable;

SHOW COLUMNS displays the following values for each table column:

Field indicates the column name.

Type indicates the column data type.

Collation indicates the collation for nonbinary string columns, or NULL
for other columns. This value is displayed only if you use the FULL
keyword.

The Null field contains YES if NULL values can be stored in the column,
NO if not.

The Key field indicates whether the column is indexed:

o If Key is empty, the column either is not indexed or is indexed only
  as a secondary column in a multiple-column, nonunique index.

o If Key is PRI, the column is a PRIMARY KEY or is one of the columns
  in a multiple-column PRIMARY KEY.

o If Key is UNI, the column is the first column of a UNIQUE index. (A
  UNIQUE index allows multiple NULL values, but you can tell whether
  the column allows NULL by checking the Null field.)

o If Key is MUL, the column is the first column of a nonunique index in
  which multiple occurrences of a given value are allowed within the
  column.

If more than one of the Key values applies to a given column of a
table, Key displays the one with the highest priority, in the order
PRI, UNI, MUL.

A UNIQUE index may be displayed as PRI if it cannot contain NULL values
and there is no PRIMARY KEY in the table. A UNIQUE index may display as
MUL if several columns form a composite UNIQUE index; although the
combination of the columns is unique, each column can still hold
multiple occurrences of a given value.

The Default field indicates the default value that is assigned to the
column.

The Extra field contains any additional information that is available
about a given column. The value is nonempty in these cases:
auto_increment for columns that have the AUTO_INCREMENT attribute; as
of MySQL 5.1.23, on update CURRENT_TIMESTAMP for TIMESTAMP columns that
have the ON UPDATE CURRENT_TIMESTAMP attribute.

Privileges indicates the privileges you have for the column. This value
is displayed only if you use the FULL keyword.

Comment indicates any comment the column has. This value is displayed
only if you use the FULL keyword.

SHOW FIELDS is a synonym for SHOW COLUMNS. You can also list a table's
columns with the mysqlshow db_name tbl_name command.

The DESCRIBE statement provides information similar to SHOW COLUMNS.
See [HELP DESCRIBE].

The SHOW CREATE TABLE, SHOW TABLE STATUS, and SHOW INDEX statements
also provide information about tables. See [HELP SHOW].

URL: http://dev.mysql.com/doc/refman/5.1/en/ … lumns.html

Offline

#3  10.11.11 09:48

Igo
Профиль

Re: [SQL] Селект названия полей таблицы. Как?

чтение мануалов помогает)

Offline

#4  10.11.11 21:40

sav
Профиль

Re: [SQL] Селект названия полей таблицы. Как?

а где написано что требуется именно в mysql?

Offline

#5  10.11.11 22:05

Re: [SQL] Селект названия полей таблицы. Как?

MS-SQL

SELECT * FROM INFORMATION_SCHEMA.Columns where TABLE_NAME = 'Foo' ... where Foo is the table name you want details for.

http://codesnippets.joyent.com/posts/show/337

Исправлено [PAUL] (10.11.11 22:05)

Offline

#6  11.11.11 09:47

Igo
Профиль

Re: [SQL] Селект названия полей таблицы. Как?

sav написал(а):

а где написано что требуется именно в mysql?

Пардон - с утра показалось что именно о нем речь)

Offline

#7  11.11.11 23:18

Re: [SQL] Селект названия полей таблицы. Как?

Igo написал(а):

sav написал(а):

а где написано что требуется именно в mysql?

Пардон - с утра показалось что именно о нем речь)

Креститесь сударь, когда кажется.

MDB

Offline

#8  12.11.11 10:08

sav
Профиль

Re: [SQL] Селект названия полей таблицы. Как?

Vega написал(а):

Igo написал(а):

Пардон - с утра показалось что именно о нем речь)

Креститесь сударь, когда кажется.

MDB

чья бы корова мычала....

задавай вопросы корректно по бд
в частности, сразу указывая тип сервера и его версию, чтобы не терять понапрасну время отвечающих

Исправлено sav (12.11.11 22:23)

Offline

#9  14.11.11 09:42

Igo
Профиль

Re: [SQL] Селект названия полей таблицы. Как?

Vega написал(а):

Igo написал(а):


Пардон - с утра показалось что именно о нем речь)

Креститесь сударь, когда кажется.

MDB

Не верующий, так что совет не уместен...

Offline

Программирование и БД » [SQL] Селект названия полей таблицы. Как? 

ФутЕр:)

© Hostel Web Group, 2002-2025.   Сообщить об ошибке

Сгенерировано за 0.236 сек.
Выполнено 11 запросов.