Computer >> Máy Tính >  >> Lập trình >> MySQL

Hiển thị tất cả các trường của một bảng trong MySQL?

Để hiển thị tất cả các trường, hãy đặt cơ sở dữ liệu với table_schema và bảng cụ thể với table_name như trong cú pháp bên dưới -

select column_name as anyAliasName from information_schema.columns
   where table_schema=database()
   and table_name=’yourTableName’\G

Đầu tiên chúng ta hãy tạo một bảng -

mysql> create table DemoTable1938
   (
   StudentId int,
   StudentName varchar(20),
   StudentAge int,
   StudentCountryName varchar(20),
   StudentMobileNumber bigint
   );
Query OK, 0 rows affected (0.00 sec)

Đây là truy vấn để hiển thị tất cả các trường của bảng -

mysql> select column_name as ALL_FIELDS from information_schema.columns
   where table_schema=database()
   and table_name='DemoTable1938'\G

Điều này sẽ tạo ra kết quả sau -

*************************** 1. row ***************************
ALL_FIELDS: StudentId
*************************** 2. row ***************************
ALL_FIELDS: StudentName
*************************** 3. row ***************************
ALL_FIELDS: StudentAge
*************************** 4. row ***************************
ALL_FIELDS: StudentCountryName
*************************** 5. row ***************************
ALL_FIELDS: StudentMobileNumber
5 rows in set (0.00 sec)