SQL Notesdoc
SQL Notesdoc
*/
.............................................*/
create table record5 (rollno int,date int,foreign key (rollno) references record4(slno))
/*joins...........................................................................*/
SELECT record1.firstname,record8.date FROM record1 INNER JOIN record8 ON record1.slno=record8.slno ORDER BY record1.firstname
SELECT record1.firstname,record8.date FROM record1 left JOIN record8 ON record1.slno=record8.slno ORDER BY record1.firstname
SELECT record1.firstname,record8.date FROM record1 right JOIN record8 ON record1.slno=record8.slno ORDER BY record1.firstname
SELECT record1.firstname,record8.date FROM record1 full JOIN record8 ON record1.slno=record8.slno ORDER BY record1.firstname
/*stored procedures.......................................................................*/
The benefits of using stored procedures in SQL Server rather than application code stored locally on client computers include: They allow
modular programming. They allow faster execution. They can reduce network traffic.
Stored procedures provide improved performance because fewer calls need to be sent to the database. For example, if a stored
procedure has four SQL statements in the code, then there only needs to be a single call to the database instead of four calls for each
individual SQL statement.
CREATE PROCEDURE pn
@city varchar(25)
AS
BEGIN
GO
@city varchar(25)
AS
BEGIN
RETURN @@ROWCOUNT;
END
GO
DECLARE @i INT
SELECT @i as countofcity
/*stored procedures.......................................................................*/
/*functions...............................................................................*/
select getdate()
/*functions...............................................................................*/
SQL | GROUP BY
The GROUP BY Statement in SQL is used to arrange identical data into groups with the help of some functions.
i.e if a particular column has same values in different rows then it will arrange these rows in a group.
Important Points:
We can use HAVING clause to place conditions to decide which group will be the part of final result-set.
we can not use the aggregate functions like SUM(), COUNT() etc. with WHERE clause. So we have to use HAVING clause if we want to use any of
these functions in the conditions.