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



How can i give the restrictions for the data entry, if i wish to enter only I ,II, III, IV in the ..

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

How can i give the restrictions for the data entry, if i wish to enter only I ,II, III, IV in the ..

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

How can i give the restrictions for the data entry, if i wish to enter only I ,II, III, IV in the ..

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

Post New Answer

More SQL Server Interview Questions

What is the full form of dql?

0 Answers  


Can we create clustered index on non primary key column

20 Answers   ABC, CTS,


Department ----------- salary Deptname 1000 A 3000 A 2000 B 3000 B 4000 C 5000 C select the deptname where salary >=5000 result should be: Deptname --------- C please post only executed query in SQL server 2005 Asked By: Md. Niyaz

3 Answers  


what is a transaction? : Sql server database administration

0 Answers  


Which database stores information about replication?

0 Answers  






Can I delete event logs?

0 Answers  


What is field in algebra?

0 Answers  


What is the STUFF function and how does it differ from the REPLACE function?

2 Answers  


Security Question- SQL DBA exparts, need your help...

3 Answers  


What is shrink log file?

0 Answers  


Every night you run a full backup after every 3 three hours you make a differential backup every hour you make an incremental backup in a worst-case scenario, how much work you can lose?

0 Answers  


What is the fillfactor concept in indexes?

0 Answers  


Categories