Search This Blog

Friday, July 13, 2012

MySQL Quiz

  1. create a database "MyDatabase"
  2. create a table "MyTable", with 4 fields[id, name, password,dateCreated]
  3. delete data from "MyTable" which have name begin with 'A'
  4. insert 3 rows of data with this information:
    • name:Ali, Johan, Frankie; password: ali123, johan123, frankie123
  5.  update data from "MyTable", change the  name to "Ali Adam", "Johan Harry", "Frankie Tom"
  6. empty the table / delete all data from "MyTable"
  7. Sort "MyTable" in descending order according to "name" field
  8. add a new field "age" to "MyTable"
  9. remove "MyTable" from "MyDatabase"
  10. u have 2 tables user(id, name, password), and activity(id, userid, activityName)
          join these 2 table and show the data of user's name and his activity.

18 comments:

  1. QUESTION 3
    DELETE FROM MyTable
    WHERE name like 'A%'

    ReplyDelete
  2. 1. Create database mydatabase;

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. create table mytable(
    id int(10)not null;
    name varchar(40) not null;
    password varchar(40) not null;
    dateCreated varchar (40) not null;
    )

    ReplyDelete
    Replies
    1. create table mytable(
      id int(10)not null;
      name varchar(40) not null;
      password varchar(40) not null;
      dateCreated varchar (40) not null;
      Primary key(id);
      )

      Delete
  5. delete from mytable

    ReplyDelete
  6. question 9

    Drop table MyTable

    ReplyDelete
  7. Quation num 7:

    SELECT * From MyTable
    Order by name desc

    ReplyDelete
  8. Question 8

    ALTER TABLE MyTable
    ADD age int(5);

    ReplyDelete
  9. QUESTION 10

    SELECT user.name, activity.activityName
    FROM user JOIN activity ON
    user.ID = activity.userID

    ReplyDelete
  10. QUESTION 4 (Vimala)
    INSERT INTO mytable
    (name, password)
    VALUES ('Ali','Ali123')
    ('Johan','Johan123')
    ('Frankie','Frankie123');

    ReplyDelete
  11. This comment has been removed by a blog administrator.

    ReplyDelete
  12. sudah update

    REPLACE INTO MyTable
    SET name = 'Ali Adam'
    WHERE name ='Ali'
    REPLACE INTO MyTable
    SET name'Johan Harry'
    WHERE name ='Johan'
    REPLACE INTO MyTable
    SET name ='Frankie Tom'
    WHERE name ='Frankie'

    ReplyDelete
    Replies
    1. This comment has been removed by the author.

      Delete
  13. may be u need the semi-colon(;) in each replacements?
    Another approach would be using UPDATE...SET...WHERE

    ReplyDelete