Create table

Written By -

Now, as you have the knowledge of how a database is created and the types of datatypes that exists, you can start working with Tables.

What are the tables in MySQL?

Tables can be described with the Attributes along with the constraints that ensure that type of value that must be entered into the tables in form of tuples and holds the authenticity of data entry.

We will be primarily working with 5 tables to ensure each type of its general use and that covers most of the queries that are operated upon.

Note: We will try to maintain a uniformity now onwards by typing the keywords in uppercase and identifiers in lower case.

The general syntax is

CREATE TABLE tablename (

attribute 1 datatype constraint,

attribute 2 datatype constraint,

attribute 3 datatype constraint,

.

.

PRIMARY KEY (attribute) );

TABLE 1

CREATE TABLE school(
Roll INT PRIMARY KEY NOT NULL, Name VARCHAR(20) NOT NULL,
DOB DATE NOT NULL, Marks INT, Grade CHAR(1),
Mobile BIGINT, State VARCHAR(20));

TABLE 2

CREATE TABLE store(
Product INT PRIMARY KEY NOT NULL, Name VARCHAR(30) NOT NULL,
Price INT NOT NULL, MFD DATE, EXP DATE, Damage VARCHAR(3), Quantity INT);

TABLE 3

CREATE TABLE air_force(
Service_No INT PRIMARY KEY, Name VARCHAR(20) NOT NULL,
Ranks VARCHAR(20) NOT NULL, Salary FLOAT, Unit VARCHAR(20),
Serving_Time INT);

TABLE 4

CREATE TABLE country(
SR_No INT PRIMARY KEY, State VARCHAR(30), Capital VARCHAR(30),
Govt VARCHAR(20), Population INT);

TABLE 5

CREATE TABLE railways(
Train_no INT PRIMARY KEY, Train_Name VARCHAR(30) NOT NULL, Source_Stn  VARCHAR(30) NOT NULL,
Destination_Stn VARCHAR(30) NOT NULL, Avg_Delay INT,
CostperKM INT);

 

Report Error/ Suggestion

Related Posts:

[yuzo_views]











CopyRight © 2019

CopyRight © 2019