23 April 2014

About Databases -- Sqlserver



Create Database:

     The SQL CREATE DATABASE statement is used to create new SQL database.

    Syntax:

     Basic syntax of CREATE DATABASE statement is as follows:

    CREATE DATABASE DatabaseName;

    Always database name should be unique within the RDBMS.

    Example:

    If you want to create new database <testDB>, then CREATE DATABASE statement would be as follows:

   SQL> CREATE DATABASE testDB;

   Make sure you have admin privilege before creating any database. Once a database is created, you can check it in the list of databases as follows:

  SQL> SHOW DATABASES;

Dropping Database:

   The SQL DROP DATABASE statement is used to drop an existing database in SQL schema.

Syntax:
    Basic syntax of DROP DATABASE statement is as follows:
    DROP DATABASE DatabaseName;

     Always database name should be unique within the RDBMS.
    Example:
    If you want to delete an existing database <testDB>, then DROP DATABASE statement would be   as follows:
 
  SQL> DROP DATABASE testDB;

   NOTE: Be careful before using this operation because by deleting an existing database would result in loss of complete information stored in the database.

    Make sure you have admin privilege before dropping any database. Once a database is dropped, you can check it in the list of databases

Select Database:

    When you have multiple databases in your SQL Schema, then before starting your operation, you would need to select a database where all the operations would be performed.

The SQL USE statement is used to select any existing database in SQL schema.

Syntax:

  Basic syntax of USE statement is as follows:

  USE DatabaseName;

  Always database name should be unique within the RDBMS.

No comments:

Post a Comment