How to add a primary key to a temporary table in SQL?

When creating temporary tables, you can define a primary key using the CREATE TABLE statement. Here is an example:

CREATE TEMPORARY TABLE temp_table (
  id INT PRIMARY KEY,
  name VARCHAR(100),
  age INT
);

In the above example, we used the PRIMARY KEY keyword to specify the id column as the primary key when creating a temporary table. You can set different columns as the primary key according to actual requirements, and choose the appropriate primary key type based on the data type of the column.

bannerAds