Showing posts with label sql. Show all posts
Showing posts with label sql. Show all posts

Friday, February 18, 2011

Grouping items in Order By Statement

I like this!!!

...
ORDER BY
CASE WHEN column = 'this' THEN 2 ELSE 1 END asc,
othercolumn asc,
another column desc
...

to group items separately and then apply a secondary sorting within each group...

Friday, May 11, 2007

SQL Queries

Specifying Identity column:

ALTER TABLE Menus
ADD MenuID numeric(18, 0) IDENTITY NOT NULL

Adding a Primary Key:

ALTER TABLE Orders
ADD CONSTRAINT PK_Orders PRIMARY KEY (OrderID)

Adding a Foreign Key: (Primary Key is in 'Orders' Table)

ALTER TABLE Roles_Menus
ADD FOREIGN KEY (RoleID) REFERENCES Roles(RoleID);