How to create a new database table using declarative schema in Magento 2.3?

From Magento 2.3, use  db_schema.xml  to create a new table for the database instead of written InstallSchema PHP class. The new database table creation/updating concept in Magento 2.3 is called declarative schema.

From Magento 2.3 You don’t need to create InstallSchema.php and UpgradeSchema.php

Now you can create a database table using a new way by creating DB schema XML file.

Location for db_schema.xml file,

You can create your custom table by below XML code,

I have taken many different types of the field for creating the new database table. You can take the only required field to create a database table.

<table>…</table> : “Used for create table in Magento 2.3+”
<column>…</column> : “Used for create different column of the table”
You can set int, text, varchar, timestamp, date, datetime, smallint, float, decimal, double etc.
<constraint>…</constraint> : “Used for set of constraint, Like primary key, foreign key, unique key.”

You can set primary key usig constraint tag

Where name is your primary key field in the above column tag.

Run Magento 2 Upgrade command to create/update table in Magento 2.3

Now you can check a new table will be generated in a database using db_schema.xml file.