Home

Transact-SQL Kerwords: SCHEMA

   

Description

A schema is an object that contains other objects. In Transact-SQL, the SCHEMA keyword is used to create and/or manage schemas. Before using it, you must create it or you can use an existing schema.

When Microsoft SQL Server is installed, it also creates a few schemas. One of the schemas is named sys. Another is called dbo. The sys schema contains a list of some of the objects that exist in your database system. One of these objects is called databases (actually, it's a view). When you create a database, its name is entered in the databases list using the same name you gave it.

The formula to programmatically create a schema is:

CREATE SCHEMA schema_name_clause [ <schema_element> [ ...n ] ]

<schema_name_clause> ::=
    {
    schema_name
    | AUTHORIZATION owner_name
    | schema_name AUTHORIZATION owner_name
    }

<schema_element> ::= 
    { 
        table_definition | view_definition | grant_statement |
        revoke_statement | deny_statement 
    }

The most important part is:

CREATE SCHEMA schema_name_clause [ <schema_element> [ ...n ] ]

Here is an example:

CREATE SCHEMA PrivateListing;
GO

To visually create a schema, right-click Schemas and click New Schema...

Object Explorer - New Schema

This would open the Schema - New dialog box. In the Schema Name text box, enter a one-word name. Here is an example:

Schema

After providing a name, you can click OK.

     
 

Home Copyright © 2007-2011 FunctionX.com