Difference between revisions of "Create DB & Table Queries"
(→Creating A Table) |
(→Creating A Table) |
||
Line 36: | Line 36: | ||
===Date data types=== | ===Date data types=== | ||
Date, Time, DateTime, TimeStamp | Date, Time, DateTime, TimeStamp | ||
+ | |||
+ | ==Example== | ||
+ | |||
+ | <syntaxhighlight lang=sql> | ||
+ | Create Table Student | ||
+ | ( | ||
+ | ID Int(6), | ||
+ | FirstName VARCHAR(16), | ||
+ | LastName VARCHAR(16), | ||
+ | Initial VARCHAR(1), | ||
+ | DoB Date() | ||
+ | ); | ||
+ | </syntaxhighlight> |
Revision as of 12:14, 24 December 2016
Contents
Creating A Database
Once you have an sql server / phpmyadmin running, you will need to create a database. This is very simple:
Create Database DBName ;
so to create a database called my_db:
Create Database my_db ;
Creating A Table
Now you have a database, you will need to create a table within your database. The create table sql should give a name for the table and then the name of each field and its data type & size.
Create Table table_name
(
field_name1 data_type(size),
field_name2 data_type(size),
filed_name3 data_type(size),
....
);
The data types available within SQL can vary and within your exam any suitable data type will be allowed:
Text data types
CHAR(x), VARCHAR(x), TEXT, STRING, Long Text, Memo
Number data types
INT(x), Tiny INT(x), Long, double, decimal, float
Date data types
Date, Time, DateTime, TimeStamp
Example
Create Table Student
(
ID Int(6),
FirstName VARCHAR(16),
LastName VARCHAR(16),
Initial VARCHAR(1),
DoB Date()
);