It also allows you to specify a list of columns to insert the data into instead of the whole. It would be more meaningful to rename the first column in the contacts table to contact_id. The command can also use a SELECT query to load data to a table. In this SELECT INTO example, we don't want the first column in the new contacts table to be called employee_id. provide us a way to look into a string and infer the type // from a substring. lb, lb+q, 1) END IF mode IS NOT NULL THEN SELECT INTO rec idxs, mode. Identifier syntax has no place for selecting schema, so if you are doing. If you find that you want to rename some of the columns within the new table rather than using the original names, you can alias the column names in the SELECT INTO statement.įor example: SELECT employee_id AS contact_id, last_name, first_name CREATE & INSERT statements to create the PostgreSQL example database for Chapter. You can just select it like any other column, you dont need to supply table name. The PostgreSQL usage of SELECT INTO to represent table creation is historical. This indeed is the usage found in ECPG (see Chapter 35) and PL/pgSQL (see Chapter 42 ). This SQL Server SELECT INTO example would select the employee_id, last_name, and first_name fields from the employees table and copy these fields along with their definitions to the new contacts table that does not yet exist.Īgain, if there were records in the employees table, then the new contacts table would be populated with the records returned by the SELECT statement. Version of database and more details for SQL Server. The SQL standard uses SELECT INTO to represent selecting values into scalar variables of a host program, rather than creating a new table. Let's look at an example that shows how to use the SELECT INTO statement in SQL Server (Transact-SQL).įor example: SELECT employee_id, last_name, first_name
0 Comments
Leave a Reply. |