Oracle&&sqlserver Get table name names primary key and data type

Source: Internet
Author: User

SQL Server obtains data types such as column name, column type, column type length, Scale,prec, and so on (Syscolumns,systypes,sysobjects are all views)

Select A.name as ColName, b.name as typename,a.length as length,a.scale as scale,a.prec as Prec from syscolumns a,systypes b, sysobjects C where A.xusertype=b.xusertype and a.id=c.id and c.name = ' TableName ' ORDER by c.id

Oracle obtains data types such as column name, column type, column type length, SCALE,PREC, etc.

Select Column_name,data_type, Data_length,data_precision,data_scale from User_tab_columns where Table_name= ' TableName '

SQL Server obtains all table names

Select Name from SysObjects Where xtype= ' U '

Oracle gets all table names

Select Tname from tab where tabtype= ' TABLE '

Gets the column, column type, column type length of the primary key in the table

Select A.name as ColName, b.name as typename,a.length as length,a.scale as scale,a.prec as Prec from syscolumns a,systy pes b, sysobjects C, information_schema. Constraint_column_usage d where A.xusertype=b.xusertype and a.id=c.id and c.name = ' TableName ' and b.name<> ' DATE ' an D a.name =d.column_name and d.constraint_name like ' pk_% '

Related Article

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.