$Three3 Posted January 15, 2010 Share Posted January 15, 2010 Hi everyone, I am new to SQL and I have been reading a book called "Learning SQL" and I am stuck on this one part of the book. It has to do with the CONSTRAINT command and I am not sure what this command does or means. The book never even explains its functionality. Here is the code from the book: CREATE TABLE person (person_id SMALLINT UNSIGNED,fname VARCHAR(20), lname VARCHAR(20), gender ENUM('M','F'), birth_date DATE, street VARCHAR(30), city VARCHAR(20), state VARCHAR(20), country VARCHAR(20), postal_code VARCHAR(20), CONSTRAINT pk_person PRIMARY KEY (person_id)); And the second table that goes along with the code above is: CREATE TABLE favorite_food (person_id SMALLINT UNSIGNED,food VARCHAR(20), CONSTRAINT pk_favorite_food PRIMARY KEY (person_id, food), CONSTRAINT fk_fav_food_person_id FOREIGN KEY (person_id)REFERENCES person (person_id)); Quote Link to comment https://forums.phpfreaks.com/topic/188589-sql-command-constraint-help/ Share on other sites More sharing options...
trq Posted January 15, 2010 Share Posted January 15, 2010 It constrains the field in question into being of a certain data. eg; A primary key constraint means that each field must contain a unique number. Quote Link to comment https://forums.phpfreaks.com/topic/188589-sql-command-constraint-help/#findComment-995803 Share on other sites More sharing options...
ksrao Posted September 21, 2010 Share Posted September 21, 2010 Hi See what is constraint ? Constraint is basically used to impose some limitation in Data base to get the uniformity in Data Base. Commonly used constraints 1. Primary key - Which uniquely identifies row in a table. 2. Foreign Key - Which is used to refers to the other table. 3. Check - To have a validation checks on input/output 4. Not Null - It will not allow null values. 5. Unique. - Repetition of the values are not allowed. To clear your basics in RDBMS go through some sql server interview questions at http://www.wiziq.com/online-class/292863-sql-server-interview-questions Thanks Regards Kolla Sanjeeva Rao OCP Oracle. Quote Link to comment https://forums.phpfreaks.com/topic/188589-sql-command-constraint-help/#findComment-1113512 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.