CREATE DATABASE using SQL
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 <School>, then CREATE DATABASE statement would be as
follows:
SQL> CREATE
DATABASE School;
Make sure you have administrative privilege before creating any database. Once a database is created, I you can check it in the list of databases as follows SQL> SHOW DATABASES
DATA
MANIPULATION LANGUAGE
CREATE TABLE
Creating a basic
table involves naming the table and defining its columns and each column's data
type.
The SQL CREATE
TABLE statement is used to create a new table.
Syntax:
Basic syntax of
CREATE TABLE statement is as follows:
CREATE TABLE
table_name(
Column 1
datatype,
Column 2
datatype,
Column 3
datatype,
Column N
datatype,
PRIMARY KEY (one
or more columns));
Example: The
following is an example which creates a CCUSTOMERS table with ID as primary key
and NOT NULL are the constrains showing that these fields cannot be NULL while
creating records in this table:
SQL> CREATE
TABLE CUSTOMER (
ID INT NOTNULL,
NAME VARCHAR (20) NOTNNULL,
AGE INT NOTNULL,
ADDRESS CHAR (25),
SALARY DECIMAL (18,2),
PRIMARY KEY
(ID));
DROP OR DELETE DATABASE
The SQL DROP DATABASE statement is used to drop
any existing database in SQL schema.
SYNTAX
Basic syntax of
Drop Database statement is a follows:
DROP DATABASE
DatabaseName;
UDATE
The
SQL Update query is used to modify the existing records in a table you use
WHERE clause with UPDATE query to update selected rows otherwise all the rows
would be affected.
SYNTAX
The
basic syntax of UPDATE query with WHERE clause is as follows:
UPDATE
table_name
SET
column1=value1,clumn2-=value2….,, columnN=valueN
WHERE[condition];
Example:
following is an example which would update ADDRESSfor a customer whose ID is 6:
SQL>
UPDATE CUSTOMERS
SET
ADDRESS = ‘Pune’
WHERE ID =6;