SQL Create Table – SQL TUTORIAL | Software Testing Material
SQL Create Table:
The SQL CREATE TABLE statement is used to create a new table in a database. Creating a table involves naming the table and defining its columns and data type of each column.
SQL Create Table Syntax:
CREATE TABLE table_name(column_name_1 data_type(size), column_name_2 data_type(size),.. , column_name_n data_type(size));
The column_name_1 parameters specify the names of the columns of the table.
The data_type parameter specifies the data type of the column (e.g. char, varchar, integer, decimal, float, etc.).
Example:
Creating a Table in the Database.
CREATE TABLE SCOREBOARD(Playername char(25),Runs int,Balls int,Sixers int,Fours int);
Copy the above Create Table statement and execute it. You could see “Command(s) completed successfully” in the result console.
To verify whether the table is created or not. You need to write Select Query. We will see Select Query in detail in later posts. Click here to view detailed post on Select Query.
SELECT * FROM SCOREBOARD
Also to view the complete table structure, use the following statement.
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'scoreboard';
Now, you have SCOREBOARD table available in the database. We could use this table SCOREBOARD to store required information.
In the next tutorial, we will see How To Retrive the data from the table using SELECT Query
Check out the complete SQL Tutorial by clicking on below link: