$Three3 0 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)); Link to post Share on other sites
trq 255 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. Link to post Share on other sites
ksrao 0 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. Link to post Share on other sites
Recommended Posts
Archived
This topic is now archived and is closed to further replies.