Home     SQL Basic     Contact Us     Site Map    

SQL BASIC

SQL SELECT

SQL WHERE

SQL DISTINCT

SQL AND

SQL OR

SQL NOT

SQL ORDER BY

SQL IN

SQL BETWEEN

SQL LIKE

SQL ALIAS

SQL AGGREGATE

>SQL COUNT

>SQL SUM

>SQL MAX

>SQL MIN

>SQL AVG

SQL GROUP BY

SQL HAVING

SQL INSERT

SQL UPDATE

SQL DELETE

SQL SELECT INTO

SQL CREATE DATABASE

SQL CREATE TABLE

SQL DROP TABLE

SQL DROP DATABASE

SQL CREATE INDEX

SQL PRIMARY KEY

SQL FOREIGN KEY

SQL ALTER TABLE

SQL TRUNCATE TABLE

SQL JOIN

SQL INNER JOIN

SQL OUTER JOIN

SQL CROSS JOIN

SQL UNION

SQL UNION ALL

SQL INTERSECT



SQL CREATE TABLE

Once the database already created, the next step will be defining the tables.Tables are like a basic building block of the database. Tables hold rows and columns of your data. SQL CREATE TABLE command is use for this.

SQL CREATE TABLE command need to complete with some contraints. That means when you create a table, you need to plan step by step. Some are the procedure you really need to take care of, which is:

1) Name it
2) Name the columns it contains
3) Specify the data type of each column
4) Specify NULL status of each column. Whether column can permits for NULL Value.
5) Define the DEFAULT value for the columns.

The SQL command is:

CREATE TABLE [TABLE NAME]
([COLUMN NAME 1] DATATYPE [NULL | NOT NULL],
 [COLUMN NAME 2] DATATYPE [NULL | NOT NULL],….
)


EXAMPLE :

Create the table name GameScores.

SQL Statement:

CREATE TABLE GameScores
( PlayerName VARCHAR(40) NOT NULL ,
Department VARCHAR(40) NOT NULL,
Scores INT NOT NULL DEFAULT 0 )