Execution Cycle it means Which error is encounter first?
by Default Sql check following cycle:
INSERT INTO #temp
(
intGlcode,
varEmpName,
varLastName,
intAge,
Emp_Code
)
VALUES (
1,
'Nirav',
'Gandhi',
18,
'0001'
)
2) Step-2 , insert data
INSERT INTO #temp
(
intGlcode,
varEmpName,
varLastName,
intAge,
Emp_Code
)
VALUES (
1,
NULL,
'Gandhi',
'abcd',
'0001'
)
In above example check, insert a null value in varEmpname and also insert 'abcd' value in intAge,both are wrong data, but when you are running above example in your screen first 'null' value error generate.
3) Step 3, DataType Length value
INSERT INTO #temp
(
intGlcode,
varEmpName,
varLastName,
intAge,
Emp_Code
)
VALUES (
1,
'Niravasasasasasasasa',
'Gandhi',
'abcd',
'0001'
)
In above example check, insert a large value in varEmpname and also insert 'abcd' value in intAge,both are wrong data, but when you are running above example in your screen first 'String or binary data would be truncated' error generate, because varEmpname datatype lenght on VARCHAR(15).
4) Step 4 --DataType
INSERT INTO #temp
(
intGlcode,
varEmpName,
varLastName,
intAge,
Emp_Code
)
VALUES (
1,
'Nirav',
'Gandhi',
99999999,
'0001'
)
In above example check, insert a 1 in intGlcode and also insert '9999999' value in intAge,both are wrong data, but when you are running above example in your screen first 'Arithmetic overflow error for data type tinyint, value = 99999999.' error generate, because intAge datatype- 'tinyint' here primary key error not Generated.
5) Step 5 --Primary key
INSERT INTO #temp
(
intGlcode,
varEmpName,
varLastName,
intAge,
Emp_Code
)
VALUES (
1,
'Nirav',
'Gandhi',
18,
'0001'
)
In above example check, insert a 1 in intGlcode and also insert '0001' value in Emp_Code,both are wrong data, but when you are running above example in your screen first 'Violation of PRIMARY KEY constraint' error generate, because intGlcode is Primary key, here Unique key error not Generated.
6) Step 6 --Unique
INSERT INTO #temp
(
intGlcode,
varEmpName,
varLastName,
intAge,
Emp_Code
)
VALUES (
2,
'Nirav',
'Gandhi',
18,
'0001'
)
--In above example Unique key error generated.
DROP TABLE #temp
by Default Sql check following cycle:
1) Null value
2) Data-type Length
3) Data-type
4) Primary Key
5) Unique Key
Please run step-by-step below example:
1) Step-1 ,Create temp table and Insert value
CREATE TABLE #temp
(
intGlcode INT PRIMARY KEY,
varEmpName VARCHAR(15) NOT NULL,
varLastName VARCHAR(15),
intAge TINYINT,
Emp_Code VARCHAR(5) UNIQUE
)
in above table intGlcode->Primary key fields, varEmpName ->inserting not null value eilds,Emp_Code->insert Unique value fields(
intGlcode INT PRIMARY KEY,
varEmpName VARCHAR(15) NOT NULL,
varLastName VARCHAR(15),
intAge TINYINT,
Emp_Code VARCHAR(5) UNIQUE
)
INSERT INTO #temp
(
intGlcode,
varEmpName,
varLastName,
intAge,
Emp_Code
)
VALUES (
1,
'Nirav',
'Gandhi',
18,
'0001'
)
2) Step-2 , insert data
INSERT INTO #temp
(
intGlcode,
varEmpName,
varLastName,
intAge,
Emp_Code
)
VALUES (
1,
NULL,
'Gandhi',
'abcd',
'0001'
)
In above example check, insert a null value in varEmpname and also insert 'abcd' value in intAge,both are wrong data, but when you are running above example in your screen first 'null' value error generate.
3) Step 3, DataType Length value
INSERT INTO #temp
(
intGlcode,
varEmpName,
varLastName,
intAge,
Emp_Code
)
VALUES (
1,
'Niravasasasasasasasa',
'Gandhi',
'abcd',
'0001'
)
In above example check, insert a large value in varEmpname and also insert 'abcd' value in intAge,both are wrong data, but when you are running above example in your screen first 'String or binary data would be truncated' error generate, because varEmpname datatype lenght on VARCHAR(15).
4) Step 4 --DataType
INSERT INTO #temp
(
intGlcode,
varEmpName,
varLastName,
intAge,
Emp_Code
)
VALUES (
1,
'Nirav',
'Gandhi',
99999999,
'0001'
)
In above example check, insert a 1 in intGlcode and also insert '9999999' value in intAge,both are wrong data, but when you are running above example in your screen first 'Arithmetic overflow error for data type tinyint, value = 99999999.' error generate, because intAge datatype- 'tinyint' here primary key error not Generated.
5) Step 5 --Primary key
INSERT INTO #temp
(
intGlcode,
varEmpName,
varLastName,
intAge,
Emp_Code
)
VALUES (
1,
'Nirav',
'Gandhi',
18,
'0001'
)
In above example check, insert a 1 in intGlcode and also insert '0001' value in Emp_Code,both are wrong data, but when you are running above example in your screen first 'Violation of PRIMARY KEY constraint' error generate, because intGlcode is Primary key, here Unique key error not Generated.
6) Step 6 --Unique
INSERT INTO #temp
(
intGlcode,
varEmpName,
varLastName,
intAge,
Emp_Code
)
VALUES (
2,
'Nirav',
'Gandhi',
18,
'0001'
)
--In above example Unique key error generated.
DROP TABLE #temp
Sir ,That is really informative post,it is nice that i know about Exception Execution Cycle now.
ReplyDeleteKeep this good work on,sir.
Sir,there is Very informative information.
ReplyDelete