SCHEMA
Example
Section titled “Example”CREATE SCHEMA sales;Output
Section titled “Output”Query OK, 1 row affected (0.00 sec)Explanation
Section titled “Explanation”This is a simple example of an SQL statement to create a new schema in MySQL. A schema, in SQL terms, is a collection of database objects, including tables, views, indexes, and procedures, associated with a database. In this example, a new schema called ‘sales’ is created.
Example
Section titled “Example”CREATE SCHEMA Accounting;Output
Section titled “Output”CREATE SCHEMAExplanation
Section titled “Explanation”In the given example, a new schema called ‘Accounting’ is created in the PostgreSQL database. The command CREATE SCHEMA is used to create a new schema. The name of the new schema is specified immediately after the command.
Example
Section titled “Example”CREATE SCHEMA Test_Schema;GO
CREATE TABLE Test_Schema.Employees( ID int IDENTITY(1,1) PRIMARY KEY, Name nvarchar(50), Title nvarchar(50));Output
Section titled “Output”Command(s) completed successfully.Explanation
Section titled “Explanation”In the example code, a new schema named Test_Schema is created, after which a new table named Employees is created within this schema. The table contains three columns: ID, Name, and Title. The ID column is set to auto increment and is also designated as the primary key for the table.
Example
Section titled “Example”CREATE SCHEMA AUTHORIZATION HR CREATE TABLE TAB_EMPLOYEE ( EMPLOYEE_ID NUMBER(6) NOT NULL, FIRST_NAME VARCHAR2(20), LAST_NAME VARCHAR2(25), EMAIL VARCHAR2(25), PHONE_NUMBER VARCHAR2(20), HIRE_DATE DATE, JOB_ID VARCHAR2(10), SALARY NUMBER(8,2), MANAGER_ID NUMBER(6), DEPARTMENT_ID NUMBER(4) ) CREATE VIEW EMP_VIEW AS SELECT FIRST_NAME, LAST_NAME FROM TAB_EMPLOYEE GRANT SELECT ON EMP_VIEW TO HROutput
Section titled “Output”This script doesn’t generate any visible output.
Explanation
Section titled “Explanation”The example code demonstrates the creation of a schema named HR along with a table TAB_EMPLOYEE and a view EMP_VIEW within the schema. EMP_VIEW is designed to display only FIRST_NAME and LAST_NAME from the TAB_EMPLOYEE table. At the end, the SELECT privilege on the view EMP_VIEW is granted to the HR user.