Is there a way to return a list of Column names, data types and if they have default values what they are?

I can get the Column names like this...

select c.column_name
from systabcol c 
key join systab t on t.table_id=c.table_id 
where t.table_name='tablename'

... but it would be really useful to be able also return the data types and if they have a default value or not

UPDATE

Figured out I can get the Column Name, Type, Nullable and Primary Key with

DESCRIBE TableName

Just need to find a way to return the default value and I've cracked the job!

Thank you

asked 19 Feb '17, 10:35

gchq's gravatar image

gchq
321262936
accept rate: 28%

edited 19 Feb '17, 10:41


SYSTABCOL."default"

permanent link

answered 19 Feb '17, 11:20

Breck%20Carter's gravatar image

Breck Carter
32.5k5407241050
accept rate: 20%

That got me on the correct path - this gives me all I need

select  *
from systabcol key join systab
where table_name = 'Customers';
(19 Feb '17, 11:38) gchq

What is max_identity? It seems to appear for autoincrement primary key columns (e.g. 44) whilst others are zero....

(19 Feb '17, 15:54) gchq
Replies hidden

Yes, that's for (global) autoincrement defaults - which need not to be primary keys. Cf. that FAQ...

(19 Feb '17, 16:32) Volker Barth
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×231

question asked: 19 Feb '17, 10:35

question was seen: 1,262 times

last updated: 19 Feb '17, 16:34