In MySQL, you can create temporary tables using the CREATE TEMPORARY TABLE statement. Temporary tables are session-specific, meaning they are only visible to the session that creates them, and their data is automatically deleted when the session ends.
Here's the syntax for creating a temporary table in MySQL:
CREATE TEMPORARY TABLE table_name (
column1 datatype1,
column2 datatype2,
...
);
- table_name: This is the name of the temporary table you want to create.
- column1, column2, etc.: These are the columns of the temporary table.
- datatype1, datatype2, etc.: These are the data types of the columns.
Here's an example of creating a temporary table in MySQL:
CREATE TEMPORARY TABLE temp_employee (
emp_id INT,
emp_name VARCHAR(100),
emp_salary DECIMAL(10,2)
);
In this example:
- We create a temporary table named temp_employee with three columns: emp_id, emp_name, and emp_salary.
- The data type of emp_id is INT, and the data types of emp_name and emp_salary are VARCHAR and DECIMAL, respectively.
After creating the temporary table, you can use it like a regular table within your session. However, keep in mind that the data in the temporary table is only visible within the session that created it, and it will be automatically deleted when the session ends.
No comments:
Post a Comment