Obtain the names of all tables and fields in the database.

Source: Internet
Author: User
1. Get all database names: SelectNameFROMMaster .. SysDatabases2. get all table names: tables: all user tables; XTypeS: All system tables; 3. Get all field names: SelectNamefromSysColumnsWhereidObjec

1. obtain all database names: Select Name FROM Master .. sysDatabases 2. obtain all table names: select name from sysobjects where type = 'U' XType = 'U': indicates all user tables; XType = 's': indicates all system tables; 3. obtain all field names: Select Name from SysColumns Where id = Objec

1. Get all database names:

Select Name FROM Master .. SysDatabases

2. Get all table names:

Select name from sysobjects where type = 'U'

XType = 'U': indicates all user tables;

XType = 's': indicates all system tables;

3. Get all field names:

Select Name from SysColumns Where id = Object_Id ('tablename ')

Obtain the table name of the current database:

Select name from sysobjects where xtype = 'U' and name <> 'dtproperties'

Obtain the field names and attributes of the current table:

Select a. name, B. xtype, B. name

From syscolumns

Inner JOIN policypes B

ON a. xtype = B. xusertype

Inner join sysobjects c ON

A. id = c. id AND c. xtype = 'U' AND c. name <> 'dtproperties' where c. name = table name

Or:

SELECT

Table name = CASE a. colorder WHEN 1 THEN c. name ELSE ''end,

Order = a. colorder,

Field name = a. name,

Id = case columnproperty (a. id, a. name, 'isidentity ') WHEN 1 then' √ 'else' END,

Primary Key = CASE

When exists (

SELECT *

FROM sysobjects

WHERE xtype = 'pk' AND name IN (

SELECT name

FROM sysindexes

WHERE id = a. id AND indid IN (

SELECT indid

FROM sysindexkeys

WHERE id = a. id AND colid IN (

SELECT colid

FROM syscolumns

WHERE id = a. id AND name = a. name

)

)

)

)

THEN '√'

ELSE''

END,

Type = B. name,

Bytes = a. length,

Length = COLUMNPROPERTY (a. id, a. name, 'precision '),

Decimal = case isnull (COLUMNPROPERTY (a. id, a. name, 'Scale'), 0)

WHEN 0 THEN''

Else cast (COLUMNPROPERTY (a. id, a. name, 'Scale') as varchar)

END,

Allow null = CASE a. isnullable WHEN 1 THEN '√ 'else'' END,

Default Value = ISNULL (d. [text], ''),

Description = ISNULL (e. [value], '')

FROM syscolumns

Left join policypes B ON a. xtype = B. xusertype

Inner join sysobjects c ON a. id = c. id AND c. xtype = 'U' AND c. name <> 'dtproperties'

Left join syscomments d ON a. cdefault = d. id

Left join sysproperties e ON a. id = e. id AND a. colid = e. smallid

Order by c. name, a. colorder

Respondent: alby-magician Level 5

I found and passed the test in ACCESS:

In ACCESS, the remarks type is represented by Memo, so the SQL statement for changing the field data type to the remarks is:

Alter table user alter column userinfo Memo

By the way, if the user table has a foreign key and the field you want to modify is a foreign key, you cannot modify it!

The following shows how to modify the SQL statement to another type (the table is tb and the field is aa ):

Alter table tb alter column aa Byte number [bytes]

Alter table tb alter column aa Long number [Long integer]

Alter table tb alter column aa Short number [integer]

Alter table tb alter column aa Single number [Single precision

Alter table tb alter column aa Double number [Double Precision]

Alter table tb alter column aa Currency

Alter table tb alter column aa Char text

Alter table tb alter column aa Text (n) Text, where n indicates the field size

Alter table tb alter column aa Binary

Alter table tb alter column aa Counter automatic number

Alter table tb alter column aa Memo remarks

Alter table tb alter column aa Time date/Time

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.