Select INTO Statement data table full table copy backup
The SELECT INTO statement is often used to create a backup copy of a table or to archive records.
SQL SELECT INTO syntax
You can insert all the columns into the new table:
SELECT *
into new_table_name [in Externaldatabase]
From Old_tablename
Or just insert the desired column into the new table:
Select COLUMN_NAME (s)
into new_table_name [in Externaldatabase]
From Old_tablename
Instance
The following statement shows that there is no problem in cross database tutorial but removing from growth column execution
SELECT * Into #tbranch the from Test.dbo.tb_test TS
--The following statement shows that there is no problem executing within the same database
Select Identity (int,1,1) as [newid],* into #tbranch from Tb_test
Make backup copies
The following example makes a backup copy of the "Persons" table: SELECT * Into Persons_backupfrom persons
The IN clause can be used to copy a table to another database: select persons.* into persons in ' Backup.mdb ' from persons
If we want to copy certain fields, we can list these fields after the SELECT statement: Select Lastname,firstname into Persons_backupfrom persons
You can also add a WHERE clause. The following example creates a table with two columns named "Persons_backup" by extracting information from the "Persons table" of people residing in "Sandnes": Select Lastname,firstname into Persons_ Backupfrom personswhere city= ' Sandnes '
You can also do this by selecting data from more than one table. The following example creates a new table called "Empl_ord_backup" that contains information obtained from the employees and orders two tables:
Select Employees.name,orders.productinto Empl_ord_backupfrom employeesinner Join
Summarize:
1. What is index: The index in a database is a set of one or more columns of values in a table and the corresponding reference
List of logical pointers to data pages that physically identify these values in the table.
2. Categories:
Unique index (unique): Two rows are not allowed to have the same index value (a unique constraint is created, and the system will
Automatically create a unique index)
Primary KEY index: Primary key index requires that each value in the primary key be unique, (create primary key to automatically create primary key
Index
Clustered index (clustered): The physical order of the rows in the table is the same as the logical (indexed) Order of the key values
, the table can contain only one clustered index, and the primary key Lieme that the clustered index
Nonclustered index (nonclustered): the physical order of the rows in the table and the logical (indexed) Order of the key values
Mismatch, there can be 249 nonclustered indexes in the table
3. Criteria for creating indexes: columns for frequent searches, columns for sorting data
Note: If there are only a few rows in the table, or if the column contains only a few different values, it is not recommended to create an index because the SQL
Server spends more time searching for data in a small table than on a line-by-row search