How to create a Table in the Database?
Before creating table collect the following information:
- Identify table name
- Identify column Names
- Identify data type of each column
- Identify length of each column
- Identify columns with null (empty) and not null(not empty) values
- Identify which columns you want as primary key, foreign keys, unique key, default key and check key constraint
- 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.
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