Home Database Mysql Tutorial 如何获取MSSQLServerOracelAccess数据字典信息_MySQL

如何获取MSSQLServerOracelAccess数据字典信息_MySQL

Jun 01, 2016 pm 01:54 PM
how surface

如果你忘记一个数据库或表的名字,或一个给定的表的结构是什么(例如,它的列叫什么),怎么办? MySQL通过提供数据库及其支持的表的信息的几个语句解决这个问题。
  
  你已经见到了SHOW DATABASES,它列出由服务器管理的数据库。为了找出当前选择了哪个数据库,使用DATABASE()函数:
  
  mysql> SELECT DATABASE();
  +------------+
  | DATABASE() |
  +------------+
  | menagerie |
  +------------+
  
  如果你还没选择任何数据库,结果是空的。
  
  为了找出当前的数据库包含什么表(例如,当你不能确定一个表的名字),使用这个命令:
  
  mysql> SHOW TABLES;
  +---------------------+
  | Tables in menagerie |
  +---------------------+
  | event        |
  | pet         |
  +---------------------+
  
  如果你想要知道一个表的结构,DESCRIBE命令是有很用的;它显示有关一个表的每个列的信息:
  
  mysql> DESCRIBE pet;
  +---------+-------------+------+-----+---------+-------+
  | Field  | Type    | Null | Key | Default | Extra |
  +---------+-------------+------+-----+---------+-------+
  | name  | varchar(20) | YES |   | NULL  |    |
  | owner  | varchar(20) | YES |   | NULL  |    |
  | species | varchar(20) | YES |   | NULL  |    |
  | sex   | char(1)   | YES |   | NULL  |    |
  | birth  | date    | YES |   | NULL  |    |
  | death  | date    | YES |   | NULL  |    |
  +---------+-------------+------+-----+---------+-------+
  
  Field显示列名字,Type是为列的数据类型,Null表示列是否能包含NULL值,Key显示列是否被索引而Default指定列的缺省值。
  
  如果你在一个表上有索引,SHOW INDEX FROM tbl_name生成有关它们的信息--表说明
  SELECT dbo.sysobjects.name AS TableName,
  dbo.sysproperties.[value] AS TableDesc
  FROM dbo.sysproperties INNER JOIN
  dbo.sysobjects ON dbo.sysproperties.id = dbo.sysobjects.id
  WHERE (dbo.sysproperties.smallid = 0)
  ORDER BY dbo.sysobjects.name
  
  --字段说明
  SELECT dbo.sysobjects.name AS TableName, dbo.syscolumns.colid,
  dbo.syscolumns.name AS ColName, dbo.sysproperties.[value] AS ColDesc FROM dbo.sysproperties INNER JOIN
  dbo.sysobjects ON dbo.sysproperties.id = dbo.sysobjects.id INNER JOIN
  dbo.syscolumns ON dbo.sysobjects.id = dbo.syscolumns.id AND
  dbo.sysproperties.smallid = dbo.syscolumns.colid
  ORDER BY dbo.sysobjects.name, dbo.syscolumns.colid
  
  --主键、外键信息(简化)
  select
  c_obj.name  as CONSTRAINT_NAME
  ,t_obj.name  as TABLE_NAME
  ,col.name  as COLUMN_NAME
  ,case col.colid
  when ref.fkey1 then 1
  when ref.fkey2 then 2
  when ref.fkey3 then 3
  when ref.fkey4 then 4
  when ref.fkey5 then 5
  when ref.fkey6 then 6
  when ref.fkey7 then 7
  when ref.fkey8 then 8
  when ref.fkey9 then 9
  when ref.fkey10 then 10
  when ref.fkey11 then 11
  when ref.fkey12 then 12
  when ref.fkey13 then 13
  when ref.fkey14 then 14
  when ref.fkey15 then 15
  when ref.fkey16 then 16
  end   as ORDINAL_POSITION
  from
  sysobjects c_obj
  ,sysobjects t_obj
  ,syscolumns col
  ,sysreferences ref
  where
  permissions(t_obj.id) != 0
  and c_obj.xtype in ('F ')
  and t_obj.id = c_obj.parent_obj
  and t_obj.id = col.id
  and col.colid  in
  (ref.fkey1,ref.fkey2,ref.fkey3,ref.fkey4,ref.fkey5,ref.fkey6,ref.fkey7,ref.fkey8,ref.fkey9,ref.fkey10,ref.fkey11,ref.fkey12,ref.fkey13,ref.fkey14,ref.fkey15,ref.fkey16)
  and c_obj.id = ref.constid
  union
  select
  i.name   as CONSTRAINT_NAME
  ,t_obj.name  as TABLE_NAME
  ,col.name  as COLUMN_NAME
  ,v.number  as ORDINAL_POSITION
  from
  sysobjects c_obj
  ,sysobjects t_obj
  ,syscolumns col
  ,master.dbo.spt_values v
  ,sysindexes i
  where
  permissions(t_obj.id) != 0
  and c_obj.xtype in ('UQ' ,'PK')
  and t_obj.id = c_obj.parent_obj
  and t_obj.xtype = 'U'
  and t_obj.id = col.id
  and col.name = index_col(t_obj.name,i.indid,v.number)
  and t_obj.id = i.id
  and c_obj.name = i.name
  and v.number > 0
  and v.number   and v.type = 'P'
  
  order by CONSTRAINT_NAME, ORDINAL_POSITION
  
  --主键、外键对照(简化)
  select
  fc_obj.name  as CONSTRAINT_NAME
  ,i.name   as UNIQUE_CONSTRAINT_NAME
  from
  sysobjects fc_obj
  ,sysreferences r
  ,sysindexes i
  ,sysobjects pc_obj
  where
  permissions(fc_obj.parent_obj) != 0
  and fc_obj.xtype = 'F'
  and r.constid = fc_obj.id
  and r.rkeyid = i.id
  and r.rkeyindid = i.indid
  and r.rkeyid = pc_obj.id
  
  ----------------- ORACLE -------------------
  --表信息
  select * from all_tab_comments t
  where owner='DBO'
  
  --列信息
  select * from all_col_comments t
  where owner='DBO'
  
  --主键、外键对照
  select OWNER, CONSTRAINT_NAME, CONSTRAINT_TYPE, TABLE_NAME, R_OWNER, R_CONSTRAINT_NAME
  from all_constraints
  where owner='DBO' and (Constraint_Type='P' or Constraint_Type='R')
  
  --主键、外键信息
  select *
  from all_cons_columns
  where owner='DBO'
  order by Constraint_Name, Position
  
  ------------------------- Access ------------------------
  //Access中的系统表MSysobjects存储属性的字段是二进制格式,不能直接分析可以采用ADO自带的OpenSchema方法获得相关信息
  
  //use ADOInt.pas
  //po: TableName
  //DBCon:TADOConnection
  /ds:TADODataSet
  
  --表信息
  DBCon.OpenSchema(siTables, VarArrayOf([Null, Null, 'Table']), EmptyParam, ds);
  
  --列信息
  DBCon.OpenSchema(siColumns, VarArrayOf([Null, Null, 'po']), EmptyParam, ds);
  
  --主键
  DBCon.OpenSchema(siPrimaryKeys, EmptyParam, EmptyParam, ds);
  
  --主键、外键对照
  DBCon.OpenSchema(siForeignKeys, EmptyParam, EmptyParam, ds);

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
How to implement the statement to view table data in MySQL? How to implement the statement to view table data in MySQL? Nov 08, 2023 pm 01:40 PM

Title: Statements and specific code examples for viewing table data in MySQL MySQL is an open source relational database management system that is widely used in applications of all sizes. In MySQL, viewing table data is a very basic operation. The following will introduce how to implement this operation through specific statements and code examples. First, we will introduce the statements and specific code examples for viewing table data through the MySQL command line tool. Suppose we have a table named "employees", the following is the pass

Is there a future for employment in clinical pharmacy at Harbin Medical University? (What are the employment prospects for clinical pharmacy at Harbin Medical University?) Is there a future for employment in clinical pharmacy at Harbin Medical University? (What are the employment prospects for clinical pharmacy at Harbin Medical University?) Jan 02, 2024 pm 08:54 PM

What are the employment prospects of clinical pharmacy at Harbin Medical University? Although the national employment situation is not optimistic, pharmaceutical graduates still have good employment prospects. Overall, the supply of pharmaceutical graduates is less than the demand. Pharmaceutical companies and pharmaceutical factories are the main channels for absorbing such graduates. The demand for talents in the pharmaceutical industry is also growing steadily. According to reports, in recent years, the supply-demand ratio for graduate students in majors such as pharmaceutical preparations and natural medicinal chemistry has even reached 1:10. Employment direction of clinical pharmacy major: After graduation, students majoring in clinical medicine can engage in medical treatment, prevention, medical research, etc. in medical and health units, medical research and other departments. Employment positions: Medical representative, pharmaceutical sales representative, sales representative, sales manager, regional sales manager, investment manager, product manager, product specialist, nurse

How to clean temp folder How to clean temp folder Feb 22, 2024 am 09:15 AM

How to clean the temp folder As we use the computer, temporary files (temp files) will gradually accumulate. These temporary files are generated when we use the computer, such as cache files when browsing the web, temporary files during software installation, etc. Failure to clean the temp folder for a long time may occupy a large amount of disk space and affect the speed of the computer. Therefore, cleaning the temp folder regularly is a necessary step to maintain computer performance. Below, we will introduce some simple ways to clean the temp folder. Method 1: Manually clean t

How to download win10 image quickly How to download win10 image quickly Jan 07, 2024 am 11:33 AM

Recently, some friends reported how to download win10 image files. Because there are so many image files on the market, what should I do if I want to find a regular file to download? Today, the editor has brought you the link to download the image and the detailed solution steps. Let’s take a look at them together. win10 image quick download and installation tutorial download link >>> System Home Ghostwin101909 image 64-bit version v2019.11<<<>>>Win10 image 64-bit v2019.07<<<>>>Win10 image 32-bit v2019.07<< <1. Search through the Internet

How to implement the statement of renaming table in MySQL? How to implement the statement of renaming table in MySQL? Nov 08, 2023 pm 12:11 PM

MySQL is a commonly used relational database management system that supports the operation of renaming tables. Normally, renaming a table carries certain risks, so you should be very careful when performing this operation. In this article, we will explore how to implement the rename table statement in MySQL and provide detailed code examples. In MySQL, you can use the ALTERTABLE statement to rename a table. The following is the basic syntax of the ALTERTABLE rename statement: ALTERTABLEo

How to check win11 computer configuration How to check win11 computer configuration Jun 29, 2023 pm 12:15 PM

How to check win11 computer configuration? The win11 system is a very practical computer operating system version. This version provides users with rich functions, allowing users to have a better computer operating experience. So many friends who use computers are curious about their computers. Specific configuration, how to perform this operation in win11 system? Many friends don’t know how to operate in detail. The editor has compiled a tutorial on how to view the win11 computer configuration below. If you are interested, follow the editor and read on! Win11 computer configuration view tutorial 1. Click the windows icon on the taskbar below or press the "windows key" on the keyboard to open the start menu. 2. Find "Settings" or "sett" in the start menu.

How to reset Win10 system How to reset Win10 system Jun 29, 2023 pm 03:14 PM

How to reset Win10 system? Nowadays, many friends like to use computers with Win10 system. However, they will inevitably encounter some unsolvable problems when using computers. At this time, you can try to reset the system. So how should you do it? Let’s follow the editor to watch the tutorial on resetting the Win10 system. Users in need should not miss it. Tutorial on resetting the Win10 system 1. Click Windows and select Settings. 2. Click Update and Security. 3. Select Restore. 4. Click Start on the right to reset this computer. The above is the entire content of [How to reset Win10 system - Tutorial on resetting Win10 system]. More exciting tutorials are available on this site!

Solve the problem of environment detection when reinstalling the system Solve the problem of environment detection when reinstalling the system Jan 08, 2024 pm 03:33 PM

How to solve the problem that the environment test fails when reinstalling the system and needs to be rewritten. The reason is: the mobile phone is poisoned. You can install anti-virus software such as Mobile Manager for anti-virus. 2. Many junk files are stored inside the mobile phone, causing the running memory of the mobile phone to be occupied. Just clear the phone cache to solve this problem. 3. The phone memory is occupied too much by saved software and files. It is no problem to delete unnecessary files and software frequently. As long as your hardware configuration meets the installation requirements, you can use the new one directly. Reinstall the system from the system disk! You can use a USB flash drive or hard disk to install, which is very fast. But the key is to use a system disk with good compatibility (supports installation in IDE, ACHI, and RAID modes), and it can be automatically and permanently activated, which has been verified. so

See all articles