How can i give the restrictions for the data entry, if i
wish to enter only I ,II, III, IV in the grade actegory of
student table?
Answers were Sorted based on User's Feedback
Answer / soorai ganesh
If u Use SQLSERVER 2005. This will helpful to you
CREATE RULE myRule AS @strGrade IN('I','II','III','IV')
GO
CREATE TABLE myTable
(
empID INT,
empName VARCHAR(50),
empGrade VARCHAR(3),
empSalary NUMERIC(9,2)
);
GO
sp_bindrule myRule, 'myTable.empGrade';
GO
INSERT INTO myTable VALUES(1,'Ganesh','I',59000) -- Valid
INSERT INTO myTable VALUES(1,'Ganesh','II',89000) -- Valid
INSERT INTO myTable VALUES(1,'Ganesh','III',99000) -- Valid
INSERT INTO myTable VALUES(1,'Ganesh','IV',259000) -- Valid
INSERT INTO myTable VALUES(1,'Ganesh','V',259000) --
Invalid
Is This Answer Correct ? | 12 Yes | 0 No |
Answer / pervej
use constraint or rules that will helps u in this query
we can also use cursor for this for insert
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / mohan
create table #test (sno int check(sno in(1,2,3)))
successfull statement:
insert into #test values(3)
failure statement :
insert into #test values(4)
error message:
INSERT statement conflicted with COLUMN CHECK
constraint 'CK__#test__sno__68E599B5'. The conflict
occurred in database 'tempdb',
table '#test________________________________________________
____________________________________________________________
___00000000D7E0', column 'sno'.
The statement has been terminated.
Is This Answer Correct ? | 0 Yes | 0 No |
Difference between uniqe index and uniqe constraint?
What meant by Performance Tuning,how can we do the performance tuning on stored procedures and tell some steps to do the performance tuning
What are the steps to take to improve performance of a poor performing query? : sql server database administration
Whether the updations made to the views reflect the original records in the table
Is a null value equal to anything? Can a space in a column be considered a null value? Why or why not?
Explain Active/Active and Active/Passive cluster configurations?
Define the one-to-one relationship while designing tables.
Which TCP/IP port does SQL Server run on?
Are semicolons required at the end of sql statements in sql server 2005?
Explain the difference between HTTP and HTTPS in database?
How do you send email on SQL Server?
What is a non clustered primary key?