Tutorials

Create Table

 How to create a Table in the Database?

Before creating table collect the following information:

  1. Identify table name
  2. Identify column Names
  3. Identify data type of each column
  4. Identify length of each column
  5. Identify columns with null (empty) and not null(not empty) values
  6. Identify which columns you want as primary key, foreign keys, unique key, default key and check key constraint
  7. Write the command to create the table


Syntax:

CREATE TABLE <Table Name>
(
        Column Name DataType(Length) Constraint,
        Column Name DataType(Length) Constraint,
        Column Name DataType(Length) Constraint, 
        Column Name DataType(Length) Constraint,
        Column Name DataType(Length) Constraint
);

Example:

CREATE TABLE Student
(
       AdmissionNumber int(5) NOT NULL Primary Key,
       SName varchar(50) NOT NULL,
       DOB date,
       fee decimal(10,2),
       mobile char(10)
);

How to see all the tables in the current Database?

Syntax or Command: SHOW TABLES;

This command will print the list of all the tables in the current database.

Command to see the Structure of any table.

Syntax: Desc <Table Name>;

Command: DESC Student;

Command to see the Data in any table.

Syntax: SELECT * FROM <TABLE NAME>;

Command: SELECT * FROM Student;

Here in the above command * is used to print all the columns of the current table.

No comments:

Post a Comment