English 中文(简体)
服务器管理演播室作为缺省选择的密码?
原标题:Order by desc as default option for SQL Server Management Studio?

Is there some way to make SQL Server Management Studio return rows descending by default ? Every time i open a table via the menu (for instance by selecting return all rows), i get the oldest rows at the top. I know i can add order by desc in the sql statement, but typing that is getting annoying :)

最佳回答

我们不能改变在SSMS中从背景菜单中生成选任考试的现有模板。

令人欣慰的是,SSMS是站得住脚的。 这意味着,你可以写一下你自己可以做的延长,你可以使用一些现有的解决办法。 我将推荐Mladen s SSMS工具包:

http://www.smstools Pack.com/

它直到最近才自由,现在仍在2008年版和之前。

问题回答

www.un.org/Depts/DGACM/index_spanish.htm 在没有定级令。

如果你看上去“最老”的话,那可能是发动机回收的最快途径,因为它是如何储存在软盘上。

除非你指明命令,否则你不能保证按此顺序行事。

ORDER BY is the only way to have results in a specific order.

令状可能是一种昂贵的操作,取决于具体表格和命令,因此没有顺序是常规的。

卡纳克人的说话是100%正确。

但是,如果你只想到<>>>>> /m> 工作,并且<> > 仅凭 开放桌子,而不是在您询问桌子时。

添加一个集群指数,第一个指数化外地按排位顺序排列。 页: 1 确实造成你需要的东西。

(如果你已经制定了关于该领域的分组索引,编辑其特性并改变其顺序。”


This is only a sensible idea if such an index is friendly to the actual use of the table. It would be self defeating to have an index that s useless programatically, just for your convenience ;)

看看《简介》的输出情况,似乎在传单上产生了疑问,因此,我不想把我的希望放在某些模板上,你可以改变某些地方。

/****** Script for SelectTopNRows command from SSMS  ******/
SELECT TOP 1000 [field1]
      ,[field2]
      ,[field3]
      ,[last_modified]
  FROM [test_database].[dbo].[t_test]

作为一种替代办法,你可以建立一个小的储存程序,采用表格的名称,然后从表格中收回数据。 假设你在表格中具有(同意)逻辑,表明记录时间的长短,那么就算不出该表的缺省令。 如果你把这种储存的程序与一个热点连接起来,那么你可以按照你的愿望,轻易从该桌上获得最高级的N记录。 我知道,这并不等同于在目标探索者中提供信息,但我个人从来不使用目标探索者,而是通过简单地在问答窗口中选择案文和迫切的CTRL-3,来获取表格的内容。

为了让你们开始,它想看像这样的情况。

IF OBJECT_ID( p_select_top_100_desc ) IS NOT NULL DROP PROCEDURE p_select_top_100_desc 
GO
CREATE PROCEDURE p_select_top_100_desc ( @table_name sysname)
AS

DECLARE @object_id int
DECLARE @order_by_col nvarchar(max)
DECLARE @sql nvarchar(max)

SELECT @object_id = Object_id(@table_name),
       @order_by_col =   

IF @object_id IS NULL
    BEGIN
        RaisError( Could not find table %s ?! , 16, 1, @table_name)
        Return(-1)
    END

-- find order by column
SELECT TOP 1 @order_by_col = c.name
  FROM sys.columns c
 WHERE c.object_id = @object_id
   AND lower(c.name) in ( modified ,  last_modified ,  change_date ,  crdate ,  etc )

-- if none found, use the identity column
SELECT @order_by_col = c.name +   DESC 
  FROM sys.columns c
 WHERE c.object_id = @object_id
   AND c.is_identity = 1
   AND @order_by_col  =   

-- if still none found, use the PK (reverse order)        
SELECT @order_by_col = @order_by_col
        + (CASE WHEN ic.index_column_id = 1 THEN    ELSE  ,  END)
        + c.name 
        + (CASE WHEN ic.is_descending_key = 0 THEN   DESC  ELSE   ASC  END)
  FROM sys.indexes i 
  JOIN sys.index_columns ic
    ON ic.object_id = i.object_id
   AND ic.index_id  = i.index_id
  JOIN sys.columns c
    ON c.object_id  = ic.object_id
   AND c.column_id  = ic.column_id
 WHERE i.object_id  = @object_id
   AND i.is_primary_key = 1
   AND @order_by_col  =   
 ORDER BY ic.index_column_id

-- actual query
SELECT @sql =  SELECT TOP 100 * FROM   
            + @table_name
            + (CASE WHEN @order_by_col =    THEN    ELSE   ORDER BY   + @order_by_col END)

PRINT @sql
EXEC (@sql)

Return 0

GO

EXEC p_select_top_100_desc  t_test 

把它与一个热点连接起来,需要去到<代码>。 页: 1 扩大树中的<条码>Key板分行,然后进入<条码> Query Shortcuts. 然后,你获得一个无记名的电网,使你能够把储存的程序与<条码>CTRL-nbr<>集成。 有些人是固定的+,在你召集了这家大楼,并迫使科索沃将只为你新开的问窗工作,而现有的窗户将与老的宗座合作。

希望有助于......

PS:如果你称其为sp_select_top_n_desc,并将其纳入主数据库,那么你就应当能够在服务器上将其全部使用,而不必在每个数据库中部署。 然而,你很可能需要转向动态-sql,然后预先确定所有<代码>sys.table。 关于<代码>DB_Name()产出的询问,否则可能会看主。 页: 1 这不是你想要的吗?

虽然官方没有为简单的线性投入发出不实命令,但Im 却获得满意的电离辐射反应中心与PK或第九类指令的缺省令。 如果我对最后的条目最感兴趣的话,请就逻辑框架发言。

CREATE TABLE [dbo].[tableA]([DateTime] [datetime] NOT NULL,
CONSTRAINT [PK_tableA] 
PRIMARY KEY CLUSTERED ([DateTime] DESC)
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, 
ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]) ON [PRIMARY]

或SSMS ......

“entergraph

like like view view view view

CREATE VIEW dbo.yourTable_vw
AS 
    SELECT TOP 100 PERCENT *
    FROM yourTable
    ORDER BY yourcolumn DESC
GO

实际上,你可以为ms子添加一个新项目,为物体探索者的环境菜单添加一个新项目。

问题: 在目标探索者中创造习俗菜单

另一种办法是,根据主编(所有服务器)中的条款,建立一个与ERER公司一起生成和执行选定声明的SP,并将一个关键的短机与这一间谍联系起来。

摘自Izik Ben-Gan s。 微软服务器2012 T-SQL Fundamentals -> Chapter 1 -> Theoretical Background -> Set Theory:

... when you write T-SQL queries against tables in database (such as a table of employees), you should think of the set of employees as a whole rather than the individual employees. ... In other words, a query against a table can return table rows in any order unless you explicitly request that the data be sorted in specific way, perhaps for presentation purpose.

SSMS不支持定制的缺省选举声明。 如果得到支持,则哪一栏按条款列出。

  1. don t have a column like CreatedDate ;
  2. or whose primary key is GUID (order is not obvious)
  3. or don t have a primary key or clustered index

Even SQL SERVER will be able to list newest data some day, it s not a nature way to think individual rows (newest/oldest) against tables. Try to use UPDATE statement combined with ORDER BY clause to update newest data.

for me - I use EF Code first, but do this whenever I create a new table: Right click table, Script Table as -> Drop & Create table, and Edit the SQL and change the key to DESC, then run the script.. done (no view or anything messy)

create table MYTESTTABLE (
    ID numeric(18, 0) identity(1, 1) not null
    ,COL1 numeric(18, 0) null
    ,COL2 numeric(18, 0) null
    ,COL3 numeric(18, 0) null
    ,COL4 numeric(18, 0) null
 CONSTRAINT [PK_MYTESTTABLE] PRIMARY KEY CLUSTERED 
(
    [ID] DESC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签