What is the purpose of a schema?

You can think of it as another logical layer that groups objects inside of a database. So tables, views, functions etc. logically don't belong to the database directly, but to a schema, so you can have objects with the same names in different schemas within a database. Even if you don't create or specify a schema yourself, most databases revert to a "default" schema that is created with the database ("public" for PostgreSQL or "dbo" for SQL Server).

Users, however, are usually created on the database level (they are "owned" by the database whereas e.g. tables are "owned" by the schema), so you can also use schemas to orgnanize access to objects between users by giving users permissions on some schemas and not others.


Recent Interview Questions | Search | Subscribe (RSS)

INTERVIEW QUESTION:

ANSWER

An XML Schema is a document that is itself described using XML and which defines how an XML document must be structured in order to conform to structured required by the a system or service which references the XML Schema.  Specifically it defines:

  • The elements that may appear
  • The attributes that may appear for each element
  • Which elements are child elements
  • The order in which child elements must appear
  • The number of child elements that may appear
  • The data types for each element or attribute
  • Default values and constant value for elements and attributes
  • Minimum and maximum occurrences of an element

The term DTD (Document Type Definition) is often used when discussing the acceptable form of XML documents. However, XML Schemas are successors to XML DTDs and have a number of benefits over DTDs.  Some of these benefits are:

  • Schemas are written in XML
  • Schemas may be extended to future additions
  • Schemas contain a richer set of rules to which data must conform
  • Schemas make it easier to validate correctness of data
  • Schemas support data types

XML schemas are able to enforce specific rules and data conformity such as:

  • Data Types – data conforms to a specific data type (string, date, numeric, boolean, etc)
  • Value restrictions – data conforms to the acceptable values (enumeration, fractionDigits, length, maxExclusive, maxInclusive, maxLength, minExclusive, minInclusive, minLength, pattern, totalDigits, whitespace, etc)
  • Element Indicators – elements conform to specific indicators (Order Indicators, Occurance Indicators, and Group Indicators) which apply rules to how many elements must appear, in what order, or adhering to a specific structure (maxOccurs, minOccurs, all, choice, sequence, etc).


Sample XML Schema


targetNamespace="http://www.somesite.com"
xmlns="http://www.somesite.com"
elementFormDefault="qualified">


  
     
        
        
        
        
            
               
                  
                  
               

            

        

      

  

Sample XML which conforms to Schema


   Joseph
   Smith
   Brian
   James
   56

ADDITIONAL ANSWERS / COMMENTS

Only registered users may post comments.

What is the purpose of schema in database?

A database schema defines how data is organized within a relational database; this is inclusive of logical constraints such as, table names, fields, data types, and the relationships between these entities.

What is the main idea of schema?

Schema is the technical term used by cognitive scientists to describe how people process, organize, and store information in their heads. Schemas, or schemata, are seen as cognitive constructs by which we organize information in our long-term memory (Widdowson, 1983).

What are the benefits of schemas?

The primary benefit of Schema Therapy is its ability to 1) help people identify and adjust their negative patterns of behaviour and 2) learn how to ensure their emotional needs are met, in a healthy way. There are four elements to the Schema Therapy model: emotional needs, schemas, coping styles and modes.

What is a schema and why do we have them?

Schema is a mental structure to help us understand how things work. It has to do with how we organize knowledge. As we take in new information, we connect it to other things we know, believe, or have experienced. And those connections form a sort of structure in the brain.