How to create a Table in SQL?

I am trying to learn SQL. I want to know the command used to create SQL tables.

You can create a table in SQL using this command.

CREATE TABLE table_name (
    column1 datatype,
    column2 datatype,
    column3 datatype,
   ....
);
1 Like

Can you provide a sample code to create a table with 5 columns and 100 rows? The table will be called “User Profiles.”

You can use this code to create the table

CREATE TABLE UserProfiles (
    UserID int,
    FirstName varchar(255),
    LastName varchar(255),
    Address varchar(255),
    City varchar(255)
);

And this to add rows to the table created, you can use this format

INSERT INTO table_name (column1, column2, column3, column4, column5)
VALUES (value1, value2, value3, value4, value5);

So, an example would be like this assuming that there are 5 columns as mentioned earlier.

INSERT INTO UserProfiles (
    UserID,
    FirstName,
    LastName,
    Address,
    City
)
VALUES
    (
        1,
        'John',
        'Doe',
        'example street, example location'
        'New York'
    ),
    (
        2,
        'Jake',
        'Dillon',
        'example street2, example location2'
        'California'
    ),

You will have to add the rows one by one by inserting the values as per your requirements.

1 Like

Thanks for your help, I will try it :slight_smile: