Updated March 31, 2023
Introduction to DBMS Table
The DBMS table is the software that helps store and reclaim the user’s data by providing securities. A table in the DBMS is the logical representation of data having a group of linked information that can be detained in the table format; the table can able to store data in identified number of columns and rows like a spreadsheet, and every row can constitute a remarkable record, and each column can constitute a field in the records, we can also say that it is an appropriate way to represent the relation between the data.
What is a DBMS table?
The DBMS is the Database Management System that provides a way to organize our data in a structured manner so that we can able to use that as per requirement; it is a group of data that can be arranged in the form of rows and columns, in which in DBMS the table is called as an association and the row in it is the tuple. The tables are the database objects that can carry the information logically because it has been organized in a row and column format. Each row in the table can store unique information. Each column can store the fields with records; the Database management system allows users to create a table, drop, and delete a table. We can also rename the table, and the DBMS table has its structured format, column names, data type, and size.
Created by using SQL DBMS table (screenshot)
If we have a table “CUSTOMER1”, in which it has column names such as “CUST_Id,” “CUST_NAME,” “CITY,” and “CONTACT_NO,” etc., and various columns can create a row, then we can able to perform some operations on the table such as Create table, Drop table, Delete table, Rename the table, let us discuss them,
-
SQL Create table
The SQL Create table is the command which can be utilized to generate the table in any database management system; for that, we have to substitute the name of the table and also have to substitute the columns and data type of the columns,
Syntax:
"CREATE TABLE "table_name" ("colm1" "data type", "colm2" "data type", "colm3" "data type",...."colmN" "data type");"
Command:
- Let us see the command for creating a table in SQL:
"CREATE TABLE CUSTOMER1(CUST_Id integer PRIMARY KEY, CUST_NAME text, CITY text, CONTACT_NO integer);"
When we run the above command, then a table has been created, which we can see; below; screenshot we check that table at the SQL server whether it has been created or not; otherwise, we can check it by using the DESC command, such as “DESC CUSTOMER1”, then it will show the regarding table and we can able to use the information which has been stored in the regarding customer table.
- After the table is created, we have to insert values as per the columns and data type by using the INSERT command, which has been given below,
In the above screenshot, we have first created a table, ‘CUSTOMER.’ Then, we inserted various columns such as ‘CUST_Id,’ ‘CUST_NAME,’ CITY, and CONTACT_NO, and by using the SELECT command, we retrieved the table information. (Note – We have used an online compiler).
-
SQL Drop table
This command has been used to delete all the information from the table; if we execute this command, all table-related information has been deleted forever, so be careful while performing this command.
Syntax:
DROP table "table_name";
-
SQL Delete table
This command has been used to delete rows from a table; if we want to delete a specific row, then we can able to put conditions in the WHERE clause; otherwise, it will delete all the records from the table, which means it wants to delete all records from the table then do not need to use WHERE clause.
Syntax:
"DELETE FROM table_name WHERE condition"
For Example:
"DELETE FROM CUSTOMER WHERE CUST_ID = 1"
How to create a DBMS table?
Let us see how to create a table in DBMS in which create table is the DDL command which has an essential structure for creating the table,
-
CREATE TABLE
This command has been utilized to generate the table per the structure set out by the user, in which the structure has several columns with its data type, and the data size can be introduced in the table.
Syntax:
CREATE TABLE table_name
(
colm1 datatype(size),
colm2 datatype(size),
colm3 datatype(size),
.....
colmN datatype(size),
PRIMARY KEY( one or more columns )
);
Example:
"CREATE TABLE STUDENTSS(Std_Id integer PRIMARY KEY, Std_Name VARCHAR(10), SUBJECT VARCHAR(10), CONTACT_NO integer(20));"
In the above example, we have created a table STUDENTS, in which we have created four columns that are Std_Id, Std_Name, Subject, and CONTACT_NO.
Data type: The data type is the kind of information we can store in the specified columns; it means we have used integer data type for Std_id, so we have to enter numerical values for the Std_id column.
Size: The size we have to provide for the specific data types will be the length of the value we can provide, which means if we have given size 10 to varchar, we can only enter the 10-character value in that specific column.
-
DESC command
This command has been used to show the structure of the table we have generated; it shows the column names, data type, size, constraints, and the default value if the value has not been provided.
Command:
Desc STUDENTS;
Conclusion
In this article, we conclude that the DBMS table can organize data in rows and columns format with the help of specific software so that users can keep their data safe and avail the data in identified manner; this article will help to understand the DBMS table concepts.
Recommended Articles
We hope that this EDUCBA information on “DBMS Table” was beneficial to you. You can view EDUCBA’s recommended articles for more information.