Showing posts with label sql server. Show all posts
Showing posts with label sql server. Show all posts

Monday, November 19, 2012

SQL Queries for Beginners

--Creating Table in SqlServer 2008

CREATE TABLE EMPLOYEE
  (
  Empid int,
  EmpName varchar(50),
  Salary  Varchar(50)
  )

--Creating Stored procedure

CREATE PROCEDURE SP_INSERTEMP
(
  @EmpName varchar(50),
  @Sal Varchar(50)
)
AS
BEGIN
--statement that you want retrieve or modify here inserting new employee in Employee table
INSERT INTO EMPLOYEE (EMPNAME,SALARY) VALUES(@EmpName,@sal)
END


--Creating Functions in sql server returning table

CREATE  FUNCTION FN_RETURNTABLE
(@tblName varchar(50)) Returns
@tblRecords table(tblNames varchar(25)
as
begin
declare @names varchar(50)

Insert into tblRecords values(@names)

return
end

Wednesday, May 4, 2011

How to insert the Records from one table to another

1.How to insert the records from one table to another?

ans:

 Here we have two options Directly inserting the Records from one table to another new table

1.SELECT COL1,COL2,COL3 INTO NEWTABLE FROM OLDTABLE
For above query one new table is created with new table name and all records on old table(table1)

2.INSERT INTO TABLE1(COL1,COL2,COL3) SELECT COL1,COL2,COL3 FROM TBALE2
It will insert the records of table2 into table1
we can use where condition also