sql playground
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

87 lines
1.3 KiB

4 years ago
  1. ## Create Table
  2. ```sql
  3. CREATE TABLE `testing` (
  4. `PID` int(11) NOT NULL,
  5. `Name` tinytext NOT NULL,
  6. `Position` tinytext NOT NULL,
  7. `Pay` double NOT NULL
  8. ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
  9. ```
  10. Generically:
  11. ```sql
  12. CREATE TABLE `<tablename>` (
  13. `<colname>` <type> NOT NULL
  14. ) ENGINE=InnoDB DEFAULT CHARSET=utf8
  15. ```
  16. ### Example
  17. ```sql
  18. CREATE TABLE `Employee` (
  19. `EmpID` int(11) NOT NULL,
  20. `EmpName` tinytext NOT NULL,
  21. `DeptID` int(11) NOT NULL
  22. ) DEFAULT CHARSET=utf8
  23. ```
  24. ## Insert Data
  25. ```sql
  26. INSERT INTO `Employee` (`EmpID`, `EmpName`, `DeptID`) VALUES ('1234', 'Becky', '1');
  27. ```
  28. Generically:
  29. ```sql
  30. INSERT INTO `<tablename>` (
  31. `<colID`, `colID`, `<colID`
  32. ) VALUES (
  33. '1234', 'Becky', '1'
  34. );
  35. ```
  36. ### Example
  37. ```sql
  38. INSERT INTO `Employee` (
  39. `EmpID`, `EmpName`, `DeptID`
  40. ) VALUES (
  41. '2345', 'Molly', '2'
  42. );
  43. INSERT INTO `Employee` (
  44. `EmpID`, `EmpName`, `DeptID`
  45. ) VALUES (
  46. '1324', 'Ted', '2'
  47. );
  48. ```
  49. EmpID | EmpName | DeptID
  50. --- | --- | ---
  51. 1234 | Becky | 1
  52. 2345 | Molly | 2
  53. 1324 | Ted | 2
  54. ## Multiple Inserts
  55. ```sql
  56. INSERT INTO `Employee` (`EmpID`, `EmpName`, `DeptID`) VALUES
  57. (1234, 'Becky', 1),
  58. (2345, 'Molly', 2),
  59. (1324, 'Ted', 2);
  60. COMMIT;
  61. ```
  62. ## View Table
  63. ```sql
  64. SELECT * FROM `Employee`
  65. ```
  66. Generically:
  67. ```sql
  68. SELECT * FROM `<tablename>`
  69. ```