How to create a table in MS Access Database

Table: – A table is an object that is used to store data in an organized format. Each Table name in MS Access must be unique. When you create a new table, Access asks you to define fields name with the data type, which is also known as column headings. In Access columns known as fields and rows are known as a record.

http://www.avitguru.com/

There are some basic rules for creating Table in MS Access Database.

(1). Each field must have a unique name, and with the data type. If we write duplicate field name then we get an error while saving the table as shown below picture.

http://www.avitguru.com/

(2). Tables have fields and record. Every field name must be unique with the data type and records collect all kinds of information in every single field.

 

We can create Table in MS Access Database from different-different techniques.

(1). Table Design – Design View

(2). SQL Query

(3). VBA Code

 

 

How to create a table in MS Access Database

How to create a table in MS Access using design view

(1). Table Design: – Table Design is a technique which is used for creating Table in MS Access Database. It is the easiest way to create Table in MS Access Database. We have to follow some steps to create a table from design view.

(A). Go To Create Tab

(B). After that, Select Table Design

http://www.avitguru.com/

(C). We have to give field name with the data type. Each field name must unique and we should not use access reserved keyword.

http://www.avitguru.com/

(D). After that, we should the table from shortcut key ctrl+s or press right click on the opened tab as shown below picture.

http://www.avitguru.com/

(E). After that, we save it and give the name as per our need.

http://www.avitguru.com/

(F). After that, Click Ok then we see our table has created in Database.

http://www.avitguru.com/

How to create a table in MS Access Database

How to create a table in MS Access from SQL

(2). SQL Query: – We create a table in MS Access Database from SQL syntax. We write SQL syntax in Data Definition and run the SQL syntax. We have to follow some steps for creating a table from Data Definition.

(A). Go To Create Tab

(B). After that, select Query Design then we see the design view of Query as shown below picture.

http://www.avitguru.com/

(C). After that, we have to select the Data Definition option for creating a table from SQL syntax as shown below picture.

http://www.avitguru.com/

(D). After that, we write SQL syntax in Data Definition.

Create Table AccessTable(

Code int,

Employee Varchar(50)

)

 

(E). After that, run this query from Run command.

http://www.avitguru.com/

(F). After that, we see that our table has created in MS Access Database.

http://www.avitguru.com/

(G). After that, we can save our query.

http://www.avitguru.com/

How to create a table in MS Access Database

 

How to create a table in MS Access using VBA

(3). VBA: – We create a table in MS Access Database from VBA Code. We write VBA Code in Module and run the VBA Code. We have to follow some steps for creating table VBA Code.

(A). Go To Create Tab

(B). After that, select Module and write basic code.

 

Sub Create_Table1()

    Dim tbl As TableDef

    Dim fld As Field

    Set tbl = CurrentDb.CreateTableDef(“AKASH”)

    Set fld = tbl.CreateField(“EMP_CODE”, dbInteger, 255)

    tbl.Fields.Append fld

    Set fld = tbl.CreateField(“EMP_NAME”, dbText, 255)

    tbl.Fields.Append fld

    Set fld = tbl.CreateField(“EMP_SALARY”, dbLong, 255)

    tbl.Fields.Append fld

    CurrentDb.TableDefs.Append tbl

    CurrentDb.TableDefs.Refresh

End Sub

http://www.avitguru.com/

(C). After that, run this Code from Run command.

http://www.avitguru.com/

(D). After that, we see that our table has created in MS Access Database.

http://www.avitguru.com/

(E). After that, we can save our Module.

http://www.avitguru.com/

How to create MS Access Database 2016

Leave a Reply

Your email address will not be published. Required fields are marked *