
Adding and Removing Attribute Table Columns
What you'll learn
- How to add and remove columns in the QGIS attribute table
- How to add data dynamically with the Field Calculator
- Setting column data types and what to watch out for
Recommended for
- Anyone who wants to organize the attribute information of their data in QGIS
- Anyone who wants to add and remove columns efficiently
- Anyone doing work where attribute table data types need careful handling
Introduction
In QGIS, you can record information about each feature in the attribute table. Partway through your work, though, you may want to add or remove attribute table columns (fields).
This article explains how to add and remove attribute table columns, and what to watch out for.
Add a column to the attribute table
The steps below add a column to the attribute table.
In the Layers panel, right-click the layer you want to add a column to and select Open Attribute Table.

The attribute table opens.

As an example, this article adds a column named NAME_JP to the data to store the names of countries in Japanese.
To add a column, the layer must be in edit mode. Click the Toggle editing mode button at the top left of the attribute table.

In edit mode, the buttons that were grayed out become available. Click the New field button.

The Add Field dialog opens.

The table below describes the items in the Add Field dialog.
| Item | Description |
|---|---|
| Name | Defines the name of the column to add. |
| Type | Defines the data type of the column to add. You can choose from the following types: - Integer (32 bit): integer - Integer (64 bit): integer64 - Decimal number (real): double - Text (string): string - Date: date If you use a GeoPackage file, you can also choose the following types: - JSON (string): string - Date Time: datetime - Binary Object (BLOB): blob - Boolean: boolean |
| Length | Sets the length of the values stored in the column. - Integer: number of digits - Decimal number (real): total number of digits - Text (string): number of characters |
| Precision | Appears when Type is set to Decimal number (real). Defines the number of significant digits after the decimal point. If Length is 10 and Precision is 3, the number has 7 digits in the integer part and 3 significant digits in the decimal part. |
In this example, the NAME_JP column stores the names of countries in Japanese, so set the following:
- Name: enter
NAME_JP - Type: select Text (string)
- Length: enter
20

When you finish, click OK to add the column to the attribute table. The values of a new column are empty (NULL).

While the layer is in edit mode, you can enter values in the new column. Select the cell you want to edit and type a value.

When you finish, click the Toggle editing mode button to exit edit mode. QGIS asks whether to save your changes. Click Save to save the edited attribute information.

Add a column with the Field Calculator
The steps above added a column with the New field button and entered the values by hand. Another method is to add a column with the Field Calculator and fill in the whole column automatically from an expression, similar to an Excel function. For example, you can add a population density column and calculate it from the population and area values at the same time.
To use the Field Calculator, click the Open field calculator button at the top right of the attribute table.

The Field Calculator dialog opens.
The dialog has two parts:
- Column settings
- Expression input

This example calculates the population density from the existing POP_EST column (the population of each country). Set the items as follows:
- Check Create a new field
- Output field name: enter
density - Output field type: select Decimal number (real)
- Output field length: enter
10, Precision: enter3 - Expression: enter
"POP_EST" / ($area / 1000000)
Note: $area is a function that calculates the area of a feature's geometry in square meters. Dividing by 1000000 gives the population density per square kilometer.

Click OK. The density column appears in the attribute table, with the population density calculated automatically.

When you finish editing, save the layer as described above.
You can use the Field Calculator to add new columns and to calculate or update the values of existing ones. It is an essential feature for processing and analyzing attribute information.
Remove a column from the attribute table
Next, here is how to remove a column from the attribute table.
Put the layer in edit mode as before, and click the Delete field button.

The Delete Fields dialog opens.
Select the column you want to remove and click OK.

QGIS removes the column you selected from the attribute table.

Exit edit mode and save to keep the changes to the attribute information.
Cautions when adding and removing columns
Keep the following points in mind when you add or remove attribute table columns.
You cannot undo a column deletion
If you save your edits after removing a column, you cannot restore the original state. For a layer loaded from a saved file, the deletion is reflected in the file as soon as you remove the column. If you remove a column by mistake, exit edit mode without saving your edits to restore the original state.
For this reason, back up the file before you experiment with adding and removing columns.
Choosing the wrong data type prevents you from storing data of other types
When you add a column, you specify the type of data it stores. If you set an integer type, the column can no longer store text.
If you store a value with a decimal part in an integer column, QGIS truncates the decimal part and stores only the integer part. To store both integers and decimals in a column, choose the Decimal number (real) type.

If the data type is text, you can enter numbers, but QGIS treats them as text. In the attribute table, text is left-aligned and numbers are right-aligned, so you can tell at a glance that the data is recognized as text.

QGIS cannot process numbers entered in a text column as numbers, for example in Field Calculator calculations or in symbology settings such as Graduated. If you need to process numeric data, use an integer or decimal number (real) column.

Be careful with column length
The length of an attribute table column depends on the data format specification of the data source where you finally save the layer.
For text, for example, the QGIS attribute table lets you set a column length of 1000. However, if the layer is a Shapefile, the Shapefile specification truncates the entered text to 255 characters. (Shapefiles also limit the length of field names, in characters. Alphanumeric names can have up to 10 characters, and Japanese names may be limited to about 3 to 5 characters depending on the encoding.)

Remember to save after editing the attributes of a temporary layer
You can also edit the attribute table of a temporary layer generated by processing features.
However, a temporary layer exists only in the memory of the PC you are working on, so when you quit QGIS, the layer information and the attribute table information are lost.
To prevent this, save the layer to a file, for example by exporting it, before you quit QGIS.
For more details on exporting layers, see this article.
Conclusion
This article introduced how to add and remove attribute table columns in QGIS, and what to watch out for. In addition to the Field Calculator, you can add columns with a table join or by running vector geoprocessing operations.


QGIS LAB is a comprehensive information hub for QGIS, the open-source GIS software. Under the concept of “Geospatial for Greater Good,” we share the knowledge and skills to open up the world through location data.


