Skip to content

Instantly share code, notes, and snippets.

@timabell
Last active October 26, 2016 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timabell/d30f062ded75c43e8d147a1aa83af192 to your computer and use it in GitHub Desktop.
Save timabell/d30f062ded75c43e8d147a1aa83af192 to your computer and use it in GitHub Desktop.
laying out sql nicely with vim tabularize - https://www.flickr.com/photos/tim_abell/30278239000/
-- Before. Note the tab characters in between the "columns" that we want in the sql text.
-- The tabs have been manually added to tell vim where we want to line things up
-- `:set list` to see tabs in vim
create table HandCraftedSqlTable (
id int identity (1, 1) not null,
parentid int not null,
somename varchar(10) not null,
someothername varchar(65) not null,
somestatus int not null constraint DF_table_tabletatusID default (1),
somereallylongcolumnname varchar(255) null,
auditid int not null,
created datetime not null constraint DF_table_Created default (getdate()),
RowVersion rowversion not null,
constraint PK_table primary key (id),
constraint FK_table_parent foreign key (parentid) references ParentWidgets (id),
constraint FK_table_CreatedBy foreign key (auditid) references Users (id)
);
-- Tab separated columns can be lined up in vim with the tabular plugin - https://github.com/godlygeek/tabular
-- Run the alignment by selecting the lines to align, and run `:Tabularize /\t`
-- Select the table-column lines, run tabularize.
-- Select the constraint lines, then run tabularize again.
-- After:
create table HandCraftedSqlTable (
id int identity (1, 1) not null,
parentid int not null,
somename varchar(10) not null,
someothername varchar(65) not null,
somestatus int not null constraint DF_table_tabletatusID default (1),
somereallylongcolumnname varchar(255) null,
auditid int not null,
created datetime not null constraint DF_table_Created default (getdate()),
RowVersion rowversion not null,
constraint PK_table primary key (id),
constraint FK_table_parent foreign key (parentid) references ParentWidgets (id),
constraint FK_table_CreatedBy foreign key (auditid) references Users (id)
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment