473,406 Members | 2,377 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

How to validate a column using stored procedure

29
I have a column name Room_type ,the valid room types are bedroom,dining room,living room,kitchen,bathroom.

I have to validate the room_type column such that only valid room types are allowed.
Aug 14 '08 #1
11 3236
code green
1,726 Expert 1GB
The problem is that invalid data has been entered.I am assuming at the front end.
This can be rendered impossible by this design
Expand|Select|Wrap|Line Numbers
  1. I would have a seperate room_types table
  2. room_types
  3. type_id   description
  4. 1            bedroom
  5. 2            dining
  6. etc
  7. Then your Room_type column can only contain a valid id.
You can easily migrate to this design and in the process filter out the invalid data.
Or maybe not. Let me know
Aug 14 '08 #2
ck9663
2,878 Expert 2GB
Then create a relationship (FK - to - PK) between the two table.

-- CK
Aug 14 '08 #3
rahulae
29
its not like that i have to write a procedure where in i should be able to insert a room and while inserting i should see that room type is valid.

valid types i have listed already.

I cannot use one more table
Aug 14 '08 #4
ck9663
2,878 Expert 2GB
It's better if you create a CONSTRAINT.

If some inserted a row on your table without using your SP, it might still have invalid values.

-- CK
Aug 14 '08 #5
rahulae
29
can you tell me how to create constraint for that because the valid room types are around 4
Aug 15 '08 #6
rahulae
29
Is there any way to validate that column without using different table and constraint
Aug 15 '08 #7
ck9663
2,878 Expert 2GB
Here are some readings.

-- CK
Aug 15 '08 #8
rahulae
29
How does that concept of constraints help solve my problem

see my problem is whenever i try to insert a room_type into a table it shouldn't allow any other types other than that i have listed.

what can i do to solve this.

will using a constraint solve this out.

if yes what type of constraint and give me an example
Aug 15 '08 #9
ck9663
2,878 Expert 2GB
A CHECK CONSTRAINT can be created for a field to ensure that the condition has to be fulfilled first before SQL SERVER allows insert/update on the table. So if you have a constraint on your room_type column that says all valid values should be IN ('BEDROOM','DINNING'), then only these two values will be inserted on your column, otherwise it will not allow the insert or update of the entire record.

-- CK
Aug 15 '08 #10
rahulae
29
plz tell me how to write it

i mean syntax
Aug 15 '08 #11
rahulae
29
how to write a check constraint expression to solve my problem
Aug 15 '08 #12

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Milo Woodward | last post by:
I have some columns of data in SQL server that are of NVARCHAR(420) format but they are dates. The dates are in DD/MM/YY format. I want to be able to convert them to our accounting system format...
1
by: .Net Sports | last post by:
i have an aliased column in an sql statement that works fine when displaying its output in a datagrid, but when I transfer the sql statement into a stored procedure , the datagrid can't see it. I...
2
by: satish | last post by:
hi, i am a learner of ms -sql server 2000, i had a doubt in stored procedures suppose i have a data base having 20 tables, all the tables have a column named--DATE can we write a store...
1
by: Fir5tSight | last post by:
Hi All, This seems to be a difficult problem for me. Hope you can help me out... I have a program whose major part is a grid that displays several columns from data obtained from a stored...
3
by: c676228 | last post by:
Hi everyone, I just realized that it's so important to validate each string, I mean 'each' before you insert data from asp page into database. I guess some customers just copy data from some...
2
by: Fir5tSight | last post by:
Hi, I have a stored procedure that looks like the follows: ------------------------------------------------------------------------------------- SELECT ClientName AS 'Client Name', Location,...
4
by: =?Utf-8?B?QmFidU1hbg==?= | last post by:
Hi, I have a GridView and a SqlDataSource controls on a page. The SqlDataSource object uses stored procedures to do the CRUD operations. The DataSource has three columns one of which -...
5
by: Ken | last post by:
I'm trying to run a loop to capture column property information from a table in my datasource. Can anybody see where this is going wrong? Dim tbl As New DataTable Dim col As DataColumn Dim x...
0
by: jeoffh | last post by:
Background: I am trying to "merge" some attributes into an existing XML column in my MS SQL 2005 database. The general idea is that I have an XML column in a table and I would like to update/delete...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.