A database contains data, and to store data we need a table. Tables are the fundamental level of a database to store data. It comprises columns, which contain a set of data values of a particular type, and rows, which contains a single data item. In this tutorial section, we will discuss on:
Let’s learn how to create table in SQL with the following example.
Table name will be ‘employee’, and this table comprises employee ID, employee name, employee salary, age, gender and the department in which the employee works
Step 1: Creating a table which involves naming the table
Step 2: Defining its columns which are part of the table
Step 3: Assigning a data type to each column
CREATE TABLE tablename( column1 datatype, column2 datatype, … columnN datatype, PRIMARY KEY(one or more columns));
where CREATE TABLE is the keyword, tablename is the name of the table name, columns1 to columnN are the set of columns, and PRIMARY KEY is a constraint followed by a semicolon
Let’s create an employee table
Create the table, employee( e_id int not null, e_name varchar(20), e_salary int, e_age int, e_gender varchar(20), e_dept varchar (20), primary key(e_id) );
It is used to delete a table from the database.
DROP TABLE TableName;
where DROP TABLE is the keyword and tablename is the name of the table followed by a semicolon
DROP TABLE test;
We have successfully created the employee table and had a quick brief on how to drop a table in SQL! In the next tutorial section, we will discuss on how to insert values into the table.
Download Interview Questions asked by top MNCs in 2019?