tags:

views:

89

answers:

4

Hello,

I'm having trouble determining the difference between CREATE SCHEMA and CREATE DATABASE. I'm of the understanding that they are the same and that it's usual to use the latter.

Is that so?

Thanks!

A: 

CREATE schema is to create a schema above the database. So can a CREATE SCHEMA create tables, views, etc etc.

CREATE SCHEMA can't create a database.

pipelinecache
+5  A: 

They are definitely not that same! A database may consist of several schemas. Schemas are basically securable objects that can contain other securable objects such as tables, views, procedures etc. Securable in this context means something that is owned by someone and to which operations can be granted.

klausbyskov
Thanks very much everyone - that helps to clarify!
Danny King
So, to clarify that my understanding is correct: An SQL schema can be thought of a particular viewpoint of a database, e.g. admininstrator (see's all tables, views, procedures), manager (sees employee-related tables, etc.), trainee (sees only basic tables, etc.)?i.e. the user-view level of the 3-tier ANSI/SPARC architecture?Or am I still misunderstood?Many thanks!
Danny King
No a schema can be thought of as a container inside a database. So a database is a container that can contain schemas and users (and possibly groups). A schema is a container that can contain a large number of different objects, such as tables, views, procedures etc. A schema is owned by a user (or group), but other users/groups can be granted the right to use the objects contained in the schema.
klausbyskov
Thanks klausbyskov!
Danny King
A: 

Create schema creates new schema while create database creates database. See this link for more information about schemas: User-Schema Separation

Giorgi
A: 

In MySQL, the two commands are synonymous from 5.0.2 upwards - this is perhaps why you had the understanding they were the same.

http://dev.mysql.com/doc/refman/5.0/en/create-database.html

However, as the others have mentioned, Schemas and Databases are different types of entity in other RDBMS.

CodeByMoonlight
Ah thank you, that is helpful! That explains my confusion with equality. Much appreciated!
Danny King