Jump to content

(Resolved) Sql


Ann_M

Recommended Posts

Hi,

 

Im trying to create a constraint which will have a fixed length of 10.

The constraint i have used is:

CHAR(10)constraint

Now according to the books "CHAR" should be a fixed length, in my terms a fixed length of 10, however, i have just tried to insert some values consisting of 9 characters and it was accepted.

 

Do i need to add something to the constraint to allow the user to input exactly a fixed length of 10?

Link to comment
Share on other sites

Hmm, I'm not sure about this, but I did a quick look on google for you:

 

http://www.devguru.com/Technologies/jetsql/quickref/constraint.html

 

This is Jet SQL so may be completely wrong, but apparently a constraint just limits what values you can put into your field, and perhaps reference other fields from different tables. Having not used it before, I'm not sure, but I don't think it's what you're after.

Link to comment
Share on other sites

Varchar(2) is the same as CHAR(2) as far as this example is concerned ;)

 

Like Faf says Ann, you need to validate the length of the string with a script before inserting it.

 

if (strlen($THE_STRING) == 10) {
 // do the insert query
} else {
 // send the user back to the form (or whatever)
 // add a warning message for good measure
}

Link to comment
Share on other sites

True, although sometimes it's more convenient to do a client-side check if it's only small and supported by most browsers.

 

If you've got a big form for instance, then you don't want to have to re-insert all the information into your fields, and although this could be overcome with some more code on your server-side application, it's easier to write a couple lines of Javascript than 30 lines of php.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.