In MariaDB, you can create a temporary table using the CREATE TEMPORARY TABLE statement. Temporary tables are session-specific and are automatically dropped when the session ends.
Here's how you can create a temporary table in MariaDB:
CREATE TEMPORARY TABLE TempTable (
ID INT,
Name VARCHAR(50)
);
This statement creates a temporary table named TempTable with columns ID and Name. The table is only visible within the current session and will be automatically dropped when the session ends.
You can then use this temporary table in your SQL queries within the same session:
INSERT INTO TempTable (ID, Name) VALUES (1, 'John'), (2, 'Alice'), (3, 'Bob');
SELECT * FROM TempTable;
To drop the temporary table explicitly when you're done using it (although this is not necessary as it will be dropped automatically when the session ends):
DROP TEMPORARY TABLE TempTable;
That's it! You have created and used a temporary table in MariaDB.
No comments:
Post a Comment