Thursday, December 5

Create Table Statement- SQL

Previously we saw how to create a database using Create Database Statement. Now lets create Tables in this " Mytest_db" database using Create Table Statement.


Create Table Statement (for creating Base Tables)

Syntax:
            Create Table table_name
                     (
                       Column_name1 datatype(size),     
                       Column_name2 datatype(size),
                       Column_name3 datatype(size),
                       Column_name4 datatype(size)
                      );

A Table is a set of rows and columns used to represent an entity. Each row represents an instance of the entity and each column for that row represents an attribute.

Eg:  
                Use Mytest_db;                    -- creates table inside database ' Mytest_db '

                Create Table employee
                     (
                        ID int,
                        Name Varchar(255),
                        Salary Money,
                        Gender char(1)
                     );


     
Result: You could see that ' employee ' table is created in ' Mytest_db '.  i.e. Only the structure of the table is created with columns ID, Name, Salary and Gender, Having no data in it. Base tables are persistent tables in a database.