Difference between revisions of "Create DB & Table Queries"

From TRCCompSci - AQA Computer Science
Jump to: navigation, search
(Creating A Table)
(Creating A Table)
Line 25: Line 25:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
The data types available within SQL can vary and within your exam any suitable data type will be allowed.
+
 
 +
The data types available within SQL can vary and within your exam any suitable data type will be allowed:
  
 
===Text data types===
 
===Text data types===

Revision as of 12:10, 24 December 2016

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