CRM is storing all attributes in Attribute table and all entities into Entity table.
In database CRM is using ColumnNumber
and IsCustomField columns to identify attribute is custom
or not.
IsCustomField=1 means custom filed.
If you want to find Entity primary text field then use following
query
select EntityView.Name, EntityView.PhysicalName,
AttributeView.Name,
AttributeView.PhysicalName from AttributeView
inner join EntityView
on
EntityView.EntityId=AttributeView.EntityId
where
ColumnNumber<33 and
IsCustomField=1
ColumnNumber < 33 are all system attributes
for that entity and ColumnNumber > 33 are all custom
attributes for that entity in Attribute Table.