Welcome to plsql4all.blogspot.com SQL, MYSQL, ORACLE, TERADATA, MONGODB, MARIADB, GREENPLUM, DB2, POSTGRESQL.

Wednesday, 17 April 2024

Create Table and Fetch Data

Here's an example of creating a table and selecting data from it:


Create Table:


CREATE TABLE Customers (

  CustomerID int,

  Name varchar(255),

  Address varchar(255),

  City varchar(255),

  Country varchar(255)

);


Insert Data:


INSERT INTO Customers (CustomerID, Name, Address, City, Country)

VALUES

  (1, 'John Smith', '123 Main St', 'New York', 'USA'),

  (2, 'Jane Doe', '456 Elm St', 'Chicago', 'USA'),

  (3, 'Bob Brown', '789 Oak St', 'London', 'UK');


Select Data:


SELECT * FROM Customers;


Output:


| CustomerID | Name | Address | City | Country |

| --- | --- | --- | --- | --- |

| 1 | John Smith | 123 Main St | New York | USA |

| 2 | Jane Doe | 456 Elm St | Chicago | USA |

| 3 | Bob Brown | 789 Oak St | London | UK |


This example creates a table called "Customers" with five columns: CustomerID, Name, Address, City, and Country. It then inserts three rows of data into the table and finally selects all the data from the table, displaying the output in a tabular format.

Please provide your feedback in the comments section above. Please don't forget to follow.