Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Creating a Table | Populating a Database
Introduction to SQL

bookCreating a Table

For storing data into an SQL-based DBMS, we first create and select a database instance. We can do so by using the following query:

CREATE DATABASE db_name;

Where db_name refers to the name of the database which we want to create.

Note

There can be more than one database instance in a DBMS, each containing their own set of tables.

Once the database is created, we can create a table using the following syntax:

CREATE TABLE table_name (
column_name1 data_type,
column_name2 data_type,
...
);

The table_name indicates the name of the table which is to be created. Inside the brackets (...), we write the column names that are to be included in the table, followed by their respective data types. Each column-datatype pair is separated by commas (,).

Following is a simple CREATE TABLE query, which creates a table called students with three columns, namely: first_name, last_name, age:

CREATE TABLE students (
	first_name VARCHAR(24),
	last_name VARCHAR(24),
	age INT
);

Following are the common datatypes in SQL:

Demonstration:

Good Practice:

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 1

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

Suggested prompts:

Ask me questions about this topic

Summarize this chapter

Show real-world examples

Awesome!

Completion rate improved to 1.72

bookCreating a Table

Swipe to show menu

For storing data into an SQL-based DBMS, we first create and select a database instance. We can do so by using the following query:

CREATE DATABASE db_name;

Where db_name refers to the name of the database which we want to create.

Note

There can be more than one database instance in a DBMS, each containing their own set of tables.

Once the database is created, we can create a table using the following syntax:

CREATE TABLE table_name (
column_name1 data_type,
column_name2 data_type,
...
);

The table_name indicates the name of the table which is to be created. Inside the brackets (...), we write the column names that are to be included in the table, followed by their respective data types. Each column-datatype pair is separated by commas (,).

Following is a simple CREATE TABLE query, which creates a table called students with three columns, namely: first_name, last_name, age:

CREATE TABLE students (
	first_name VARCHAR(24),
	last_name VARCHAR(24),
	age INT
);

Following are the common datatypes in SQL:

Demonstration:

Good Practice:

Everything was clear?

How can we improve it?

Thanks for your feedback!

SectionΒ 4. ChapterΒ 1
some-alt