How to Create a Database, a Table, and Insert some data using SQL?

How to Create a Database, a Table, and Insert some data using SQL?

Using SQL Commands we can create Databases, Tables, and Insert data into Tables...

SQL Commands can be divided in to 4 categories,
1. Data Definition Language
2. Data Manipulation Language
3. Data Control Language
4. Transaction Control Language

Step 1: Create a Database 
I
t is Data Definition Language Operation.

Syntax:
Create Database Database_Name;

Example:
Create Database gcreddy;
-----------------------------------
Step 2: Create a Table in the Database

It is also Data Definition Language Operation.

Before Create a table first Use/Select database...

Syntax:
Create Table table_name ( column1 datatype, column2 datatype, column3 datatype,
....
.;

Example:
Create Table abcd(
Id int,
Name varchar (50)
);
-----------------------------------
Step 3: Insert a Record in to the Table

It is Data Manipulation Language Operation.

Syntax:
Insert Into table_Name (column1, column2, colum3....)
Values (Value1, Value2, Value3...);

Example:
Insert Into abcd
(Id, Name)
Values (1, 'Ramesh');

Select * From abcd;
-----------------------------------
Step 4: Insert multiple Records...

Example:
Insert Into abcd
(Id, Name)
Values (2, 'Venkat'),
(3, 'Ramu'),
(4, 'Bhasha'),
(5, 'David')
;
-----------------------------------
Step 5: Check the Table using Select statement...

Syntax:
Select * From table_Name;

Example:
Select * From abcd;

Database Table with Records...

Example:
Insert Into abcd
(Id, Name)
Values (2, 'Venkat'),
(3, 'Ramu'),
(4, 'Bhasha'),
(5, 'David')
;
x

0 comments:

Post a Comment