Solved

Alter a table, Order By ASC

Posted on 2013-02-01
3
271 Views
Last Modified: 2013-02-01
Is it possible to add a constraint to a table column that would sort based on date?
I'm using a uniqueidentifer as my primary key, so I want to order by ascending date on SubmitDate column.

ALTER TABLE MyTableName
ADD Constraint ORDER BY (SubmitDate)

SubmitDate is the column name.

I'm using SQL Server.

Thanks.
0
Comment
Question by:javierpdx
  • 2
3 Comments
 
LVL 65

Accepted Solution

by:
Jim Horn earned 500 total points
ID: 38845615
Nope nope nope nope nope.
Tables are only containers of data, and do not contain logic that deals with how that data is sorted.

To view a sorted table, create a view that has

SELECT TOP 100 PERCENT whatever
FROM MyTableName
ORDER BY SubmitDate

btw long story where TOP must be in a view, just trust me on this one..
0
 

Author Closing Comment

by:javierpdx
ID: 38845620
Thanks.
0
 
LVL 65

Expert Comment

by:Jim Horn
ID: 38845625
Thanks for the grade.  Good luck with your project.  -Jim
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now