treffynnon/sqlstyle.guide

[just suggestion] from gitlab style (indentation 2 spaces)

seunggabi opened this issue · 1 comments

suggestion

  • I like sql, I use sql every day.
  • I think indentation meaningful in sql style.
  • but, this repository guide hasn't union indent style.
  • so, I suggest 2 spaces indentation.
  • Please, check my idea.
  • P.S.
    • I respect another style. (everything has each by each style.)
    • but, if we can make good rule possibly (for readability, common unity)
    • indentation is powerful tool. (for readability, maintainability)
  • thx for reading.

reference

example

SELECT file_hash  -- stored ssdeep hash
FROM file_system
WHERE file_name = '.vimrc';
/* Updating the file record after writing to the file */
UPDATE file_system
SET
  file_modified_date = '1980-02-22 13:19:01.00000',
  file_size = 209732
WHERE file_name = '.vimrc';
SELECT first_name
FROM staff;
SELECT first_name AS fn
FROM staff AS s1
  JOIN students AS s2
    ON s2.mentor_id = s1.staff_num;
SELECT SUM(s.monitor_tally) monitor_total
FROM staff s;
SELECT model_num
FROM phones p
WHERE p.release_date > '2014-09-30';
SELECT
  f.species_name,
  AVG(f.height) AS average_height, 
  AVG(f.diameter) AS average_diameter
FROM flora f
WHERE f.species_name = 'Banksia'
  OR f.species_name = 'Sheoak'
  OR f.species_name = 'Wattle'
GROUP BY f.species_name, f.observation_date)
UNION ALL
SELECT 
  b.species_name,
  AVG(b.height) AS average_height, 
  AVG(b.diameter) AS average_diameter
FROM botanic_garden_flora AS b
WHERE b.species_name = 'Banksia'
  OR b.species_name = 'Sheoak'
  OR b.species_name = 'Wattle'
GROUP BY b.species_name, b.observation_date);
SELECT
  a.title,
  a.release_date,
  a.recording_date
FROM albums AS a
WHERE a.title = 'Charcoal Lane'
  OR a.title = 'The New Danger';
INSERT INTO albums (title, release_date, recording_date)
VALUES
('Charcoal Lane', '1990-01-01 01:01:01.00000', '1990-01-01 01:01:01.00000'),
('The New Danger', '2008-01-01 01:01:01.00000', '1990-01-01 01:01:01.00000');
UPDATE albums
SET release_date = '1990-01-01 01:01:01.00000'
WHERE title = 'The New Danger';
SELECT 
  a.title,
  a.release_date, 
  a.recording_date, 
  a.production_date -- grouped dates together
FROM albums AS a
WHERE a.title = 'Charcoal Lane'
  OR a.title = 'The New Danger';
SELECT r.last_name
FROM riders AS r
  INNER JOIN bikes AS b
    ON r.bike_vin_num = b.vin_num
      AND b.engine_tally > 2
  INNER JOIN crew AS c
    ON r.crew_chief_last_name = c.last_name
      AND c.chief = 'Y';
SELECT
  r.last_name,
  (
    SELECT MAX(YEAR(championship_date))
    FROM champions AS c
    WHERE 1=1
      AND c.last_name = r.last_name
      AND c.confirmed = 'Y'
  ) last_championship_year
FROM riders r
WHERE 1=1
  AND r.last_name IN
  (
    SELECT c.last_name
    FROM champions AS c
    WHERE YEAR(championship_date) > '2008'
      AND c.confirmed = 'Y'
  );
SELECT 
  CASE postcode
    WHEN 'BN1' THEN 'Brighton'
    WHEN 'EH1' THEN 'Edinburgh'
  END city
FROM office_locations
WHERE 1=1
  AND country = 'United Kingdom'
  AND opening_time BETWEEN 8 AND 9
  AND postcode IN ('EH1', 'BN1', 'NN1', 'KW1');
CREATE TABLE staff (
  PRIMARY KEY (staff_num),
  staff_num INT(5) NOT NULL,
  first_name VARCHAR(100) NOT NULL,
  pens_in_drawer INT(2) NOT NULL,
  CONSTRAINT pens_in_drawer_range
  CHECK(pens_in_drawer BETWEEN 1 AND 99)
);

cc

Thanks - if you wish to use two spaces then please feel free to fork the guide. As it stands sqlstyle.guide will continue with it's current indentation style.