天天看點

SQL SERVER的一些操作

最近忙着折騰一些項目,要用到一些資料庫,主要在Oracle ,mysql,sqlserver 和 sqlite 這四類資料庫來回折騰,指令常弄混,還是記下來好 !

SQL server 的操作:

在CMD視窗下,直接輸入sqlcmd,即可使用控制台操作:

登陸資料庫

sqlcmd -S 資料庫伺服器位址 -U 使用者名 -P 密碼 

或 

sqlcmd -S 資料庫伺服器位址\資料庫執行個體名 -U 使用者名 -P 密碼

查詢資料庫

    1. 檢視有哪些資料庫 

      >1 SELECT name FROM sys.databases 

      >2 GO 

      每次輸入sql語句都要打一行go,

    2. 切換資料庫上下文 

      USE 資料庫名

    3. 檢視資料庫裡有哪些表 ,隻有切換完後才能檢視所在資料庫下的全部表

      SELECT name FROM sysobjects  type ='U'

    4. 檢視表中的列名 

      SELECT name FROM syscolumns WHERE id=object_id(‘表名’)

    5. 其他 

      sql server 數表: 

      select count(1) from sysobjects where xtype=’U’

      數視圖: 

      select count(1) from sysobjects where xtype=’V’

      數存儲過程 

      select count(1) from sysobjects where xtype=’P’

    6. 檢視表結構

        sp_help  表名

       sp_columns 表名

在SSMS中的操作以及sqlcmd中的語句,自行開發使用的pymssql結果顯示有所不同,以實際為準!

轉載于:https://www.cnblogs.com/szchenh2010/p/9643914.html