SQL database

Discussion in 'Homework' started by DarkMessiah7, Nov 30, 2015.

  1. DarkMessiah7

    DarkMessiah7 Well-Known Member

    So i need to create A bunch of tables and i have some questions.

    WTF are constraints ? How they work ?

    and how would i fill a table like this ?

    Code:
    create table workers(
    A_T varchar(10),name varchar(30),birthdate date,phone double,street varchar(10),number integer,
    city varchar(10),
    primary key(A_T));
    the numbers in parentheses limits the number of numbers letter in the key value? I dont really care about that since it works but it might cause problems later.

    TIA. If i do this before midnight ill have hope for the semester.
     
  2. Eli_Green

    Eli_Green Well-Known Member

    yeah, parentheses is your character limit there.

    I haven't done SQL for a while, but I recall this website being really helpful:

    http://www.w3schools.com/sql/default.asp

    You might have to adapt the code to whatever you are using, but the principals are the same.

    ---------- Post added at 10:13 AM ---------- Previous post was at 10:08 AM ----------

    this is the syntax for inserting, where values are placed in the order of their columns.

    i.e. (A_T, name, birthdate, ...)
     
  3. Rickaby

    Rickaby Well-Known Member

    The number in the parenthesis represents the maximum number of characters allowed allowed for each entry in that specific column.

    Constraints are used to determine rules in the database afaik. For instance, NOT NULL is a constraint which indicates that a column cannot use null values.
     
  4. DarkMessiah7

    DarkMessiah7 Well-Known Member

    Cool. Ty guys :D i also called my classmate who did it yesterday and she'll be coming to help me finish it . Im going to insert the values and correct syntax till then.

    Id rather copy it and be done with it but id feel like a prick getting credit and doing nothing.
     
  5. frazz0402

    frazz0402 Well-Known Member

    There are several types of constraints. For example a NOT NULL constraint means a certain value isn't allowed to be empty, primary key/unique constraints don't allow the same value to be repeated for that field or foreign key constraints that force a specific field in one table to always match 1 of the fields in another table. These things exist to ensure your data integrity (i.e make sure everything makes sense and you don't end up with wrong data that would violate your schema definitions).

    As for your table, those are just definitions for each field (column). They're always in the format of: field name, data type and size. VARCHAR(30) can be a string of up to 30 characters and letters.
     
  6. DarkMessiah7

    DarkMessiah7 Well-Known Member

    I edited it in notepad++ to avoid messing things up and it seems like somethings off. I dont get why some colours don't change. Its like im forgetting parentheses or ''

    Damn its 4-5 pages and it messes with my head. Thankfully the professor wont be counting typos and minor syntax errors. He might even give us more days to do fixes.
     
  7. frazz0402

    frazz0402 Well-Known Member

    Why not insert/create that data into an actual SQL database and let the parser tell you what's wrong with it instead?