SQL Server – Copy data from one table to another

To copy data from one table to an existing table, use INSERT INTO SELECT and specify the column list: If the columns are the exact same in the two tables (and there are no identity columns), you don’t need to specify the column list: When the table doesn’t exist, use SELECT INTO, specifying which columns … Read more

SQL Server – How to use INFORMATION_SCHEMA to find database metadata

Let’s say you want to find all columns in a database that have the word ‘Name’ in the column name. You can query INFORMATION_SCHEMA.COLUMNS, like this: This query returns the following five rows showing the table name, column name, and column data type: TABLE_NAME COLUMN_NAME DATA_TYPE Actors FirstName nvarchar Actors LastName nvarchar Actors Fullname nvarchar … Read more