SCRIPTS
--A SQL SCRIPT IS A
.SQL FILE (OR OTHER) THAT CONTAINS SQL COMMANDS TO EXECUTE.
--WRITE SOME SQL
COMMANDS
--FILE-->SAVE
[SAVE SOMEWHER LETS SAY DESKTOP]. YOU CAN OPEN THAT LATER AND EXECUTE.
--SO SCRIPT
CONTAINS SERIES OF STATEMENTS
--THE STATEMENTS
CAN BE LIKE
--SELECT * FROM
EMPLOYEE ;
--USE OF SEMICOLUMN
IS OPTIONAL
--NOW THE
SEMICOLUMN INDICATES THE TERMINATION OF THE STATEMENT. WE RARELY USE THIS
SEMICOLUMN.
--WE USE SEMICOLUMN
IN COMMON TABLE EXPRESSION
GO
IT IS A SPECIAL
COMMAND THAT IS A BATCH TERMINATOR.
A BATCH IS A SET OF
SQL COMMANDS THAT GET SENT TO SQL SERVER IN ONE NETWORK PACKET
à LETS UNDERSTAND THIS CLEARLY
SELECT * FROM EMPLOYEE
GO
SELECT * FROM FRIENDS
GO
à SQL SERVER UNDERSTANDS AS BELOW
SELECT * FROM EMPLOYEE
GO
OK THIS IS TAKEN AS
ONE BATCH. THEN ITS EXECUTED
THEN THE NEXT BATCH
STARTS
SELECT * FROM FRIENDS
GO
NOW THIS WILL
CLEAR THE CONCEPT..I AM EXECUTING THE BELOW STATEMENT IN NEW QUERY WINDOW
SELECT * FROM EMPLOYEE
GO
SELECT *
FROM FRIENDS
WHERE NAME LIKE '%SIBA%'
GO
SELECT * FROM EMPLOYEE
GO
SELECT *
FROM FRIENDS
GO
WHERE NAME LIKE '%SIBA%'
O/P
(9 row(s) affected)
(4 row(s) affected)
Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the
keyword 'WHERE'.
EXPLANATION
à IT EXECUTES THE FIRST BATCH
SELECT * FROM EMPLOYEE
GO
à THEN IT EXECUTES THE SECOND BATCH
SELECT *
FROM FRIENDS
GO
à THEN IT FINDS
WHERE NAME LIKE '%SIBA%' [SO WE
GET ERROR MESSAGE LIKE :Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the
keyword 'WHERE'. ]
à BUT WAIT IT SHOLWS US LINE NUMBER 1 AS
ERROR.BUT ACTUALLY ITS NOT LINE NUMBER 1.
à SQL SERVER COMPLETES BOTH BATCH
SUCCESSFULLY AND THEN IT FINDS THE ERROR THAT IS LINE NUMBER 1[LINE NUMBER IN
REFERENCE TO BATCH].BUT BELOW BELOW IN MANAGEMENT STUDIO IT SHOWS ACTUAL LINE[16].
AFTER EXECUTE A
TICK SYMBOL IS THERE. THE SYMBOL IS CALLED PARSE
SELECT * FROM EMPLOYEE
GO
SELECT *
FROM FRIENDS
GO
WHER NAME LIKE '%SIBA%'
à CLICK ON PARSE
Msg 156, Level 15, State 1, Line 1
Incorrect syntax
near the keyword 'LIKE'.
à IT SHOWS LINE NUMBER 1. AGAIN BECAUSE OF
TWO BATCHES ARE COMPLETED..AND THEN ERROR
SELECT * FROM EMPLOYEE
SELECT *
FROM FRIENDS
WHER NAME LIKE '%SIBA%'
-Ã CLICK ON PARSE
-Msg 102, Level 15,
State 1, Line 4
Incorrect syntax
near 'NAME'.
à NO GO STATEMENT SO LINE NUMBER 4
=== J J J J J J J J HOPE YOU ENJOYED IT J J J J J J J J ====
SEE YOU
No comments:
Post a Comment