Backup/Copy a table in SQL using query

Backup/Copy a table in SQL using query

Copy all columns into the new table:

SELECT * INTO NewTableName FROM OldtableName;
e.g.
SELECT * INTO Emp_DetailsBkup FROM Emp_Details;


Copy selected columns to new table

SELECT Col1, Col2, Col3 INTO Emp_DetailsBkup FROM Emp_Details;
e.g.

SELECT Emp_Name, Emp_Id, Address INTO Emp_DetailsBkup FROM Emp_Details;


Copy selected columns to new table with Where clause
SELECT * INTO NewTableName FROM OldtableName where clause;
e.g.

SELECT * INTO Emp_DetailsBkup FROM Emp_Details where id >10;

Why we can't execute a stored procedure from a User Defined function(UDF)

Functions cannot "touch" any database but read them only. Stored procedures can do anything and everything with databases. You ...