SHARE
TWEET

solution mysqlsys fixed

a guest Apr 25th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Home / Basic MySQL Tutorial / MySQL Insert
  2. MySQL Insert
  3. ?
  4. Summary: in this tutorial, you will learn how to use MySQL INSERT statement to add one or more rows to a table.
  5.  
  6. Introduction to the MySQL INSERT statement
  7. The INSERT statement allows you to insert one or more rows into a table. The following illustrates the syntax of the INSERT statement:
  8.  
  9. 1
  10. 2
  11. INSERT INTO table(c1,c2,...)
  12. VALUES (v1,v2,...);
  13. In this syntax,
  14.  
  15. First, specify the table name and a list of comma-separated columns inside parentheses after the INSERT INTO clause.
  16. Then, put a comma-separated list of values of the corresponding columns inside the parentheses following the VALUES keyword.
  17. The number of columns and values must be the same. In addition, the positions of columns must be corresponding with the positions of their values.
  18.  
  19. To add multiple rows into a table using a single INSERT statement, you use the following syntax:
  20.  
  21. 1
  22. 2
  23. 3
  24. 4
  25. 5
  26. 6
  27. INSERT INTO table(c1,c2,...)
  28. VALUES
  29.    (v11,v12,...),
  30.    (v21,v22,...),
  31.     ...
  32.    (vnn,vn2,...);
  33. In this syntax, rows are separated by commas in the VALUES clause.
  34.  
  35. MySQL INSERT examples
  36. Let’s create a new table named tasks for practicing the INSERT statement.
  37.  
  38. 1
  39. 2
  40. 3
  41. 4
  42. 5
  43. 6
  44. 7
  45. 8
  46. 9
  47. CREATE TABLE IF NOT EXISTS tasks (
  48.     task_id INT AUTO_INCREMENT,
  49.     title VARCHAR(255) NOT NULL,
  50.     start_date DATE,
  51.     due_date DATE,
  52.     priority TINYINT NOT NULL DEFAULT 3,
  53.     description TEXT,
  54.     PRIMARY KEY (task_id)
  55. );
  56. Using simple INSERT statement example
  57. The following statement adds a new row to the tasks table:
  58.  
  59. world wide web
  60.  
  61. 1
  62. 2
  63. 3
  64. 4
  65. INSERT INTO
  66.  tasks(title,priority)
  67. VALUES
  68.  ('Learn MySQL INSERT Statement',1);
  69. MySQL returns the following message after the statement executed:
  70.  
  71. 1
  72. 1 row(s) affected
  73. It means that one row has been inserted into the tasks table successfully.
  74.  
  75. You can verify it by using the following query:
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top