![]() Since the SELECT statement support all clauses that you'd usually employ in your SQL statements, including the WHERE and ORDER BY clauses, we can limit what we copy over by supplying a condition in our statement. It's a way to do, in one line of code, the exact same thing as we did using two separate statements above. The full syntax for the statement is:ĬREATE TABLE new_tbl SELECT * FROM orig_tbl The CREATE TABLE statement provides a way to create one table from another by adding a SELECT statement at the end of the CREATE TABLE statement. Introducing the CREATE TABLE AS SELECT Statement ![]() While the above procedure works perfectly well, there's an easier way to copy a table into a new one using a variation of the CREATE TABLE statement! We'll learn how to use it here today. ![]() Then, the database populates data with the results of the SELECT statement to the new table. The structure of the new table is defined by the result set of the SELECT statement. In the first statement, the database creates a new table with the name indicated in the CREATE TABLE statement. In SQL, one would typically use CREATE TABLE and SELECT statements as follows: ![]() There are many times where one needs to copy data from an existing table to a new one, for example, to back up data or to replicate data in one environment in another, as one might do for testing purposes. Copying a Table to a New Table using Pure SQL by Robert Gravelle ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |