How to obtain mssqlservercancelaccess data dictionary information _ MySQL

Source: Internet
Author: User
How to obtain MSSQLServerOracelAccess data dictionary information? what if you forget the name of a database or table, or the structure of a given table (for example, what is its column name? MySQL solves this problem by providing several statements about the database and its supported tables.
  
You have seen show databases, which lists the DATABASES managed by the server. To find the DATABASE selected, use the DATABASE () function:
  
Mysql> select database ();
+ ------------ +
| DATABASE () |
+ ------------ +
| Menagerie |
+ ------------ +
  
If you have not selected any database, the result is blank.
  
To find out what table the current database contains (for example, when you cannot determine the name of a table), run the following command:
  
Mysql> show tables;
+ --------------------- +
| Tables in menagerie |
+ --------------------- +
| Event |
| Pet |
+ --------------------- +
  
If you want to know the structure of a table, the DESCRIBE command is very useful; it displays information about each column of a table:
  
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 indicates the column name. Type indicates the column data Type. Null indicates whether the column can contain NULL values. Key indicates whether the column is indexed and Default indicates the Default value of the column.
  
If you have an INDEX on a table, show index from tbl_name generates information about them-table description
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
  
-- Field description
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
  
-- Primary key and foreign key information (simplified)
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 <= I. keycnt
And v. type = 'p'
  
Order by CONSTRAINT_NAME, ORDINAL_POSITION
  
-- Primary key and foreign key comparison (simplified)
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 -------------------
-- Table information
Select * from all_tab_comments t
Where owner = 'dbo'
  
-- Column information
Select * from all_col_comments t
Where owner = 'dbo'
  
-- Primary key and foreign key comparison
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 ')
  
-- Primary key and foreign key information
Select *
From all_cons_columns
Where owner = 'dbo'
Order by Constraint_Name, Position
  
------------------------- Access ------------------------
// The System table MSysobjects in Access stores the attribute fields in binary format. you can use the OpenSchema method provided by ADO to obtain relevant information without direct analysis.
  
// Use ADOInt. pas
// Po: TableName
// DBCon: TADOConnection
/Ds: TADODataSet
  
-- Table information
DBCon. OpenSchema (siTables, VarArrayOf ([Null, Null, 'table']), EmptyParam, ds );
  
-- Column information
DBCon. OpenSchema (siColumns, VarArrayOf ([Null, Null, 'Po']), EmptyParam, ds );
  
-- Primary key
DBCon. OpenSchema (siPrimaryKeys, EmptyParam, EmptyParam, ds );
  
-- Primary key and foreign key comparison
DBCon. OpenSchema (siForeignKeys, EmptyParam, EmptyParam, ds );

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.