if object_id('tb') is not nulldrop table tbgocreate table tb(name varchar(25))insert into tbselect 'z,y,w,c' union allselect '1,2,3,4' select name=substring(a.name,b.number,(charindex(',',a.name+',',b.number))-b.number) from tb a,master..spt_values
SELECT 表名=case when a.colorder=1 then d.name else '' end, 表說明=case when a.colorder=1 then isnull(f.value,'') else '' end, 欄位序號=a.colorder, 欄位名=a.name, 標識=case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then '√'else '' end, 主鍵=case when exists(
假設建立一個COURSE表,create table dbo.COURSE(COURSENO int identity(1,1),CNAME varchar(30),CDATE varchar(20),)然後插入一行值,insert into dbo.COURSE values('Basic Accounting','11-JAN-89')然後又刪除掉,delete from COURSE WHERE CNAME='Basic Accounting' 然後又插入一行值,insert into
--查看錶的屬性select * from sysObjects where [Name] = 'section' --用法 if exists ( select * from sysObjects where [Name] = 'section' and xtype='U' ) Drop Table table1 go Create table1 ( )--擷取所有使用者表select Name from sysobjects where xtype='u' and
--1. 建立自訂函數:從最後一個特定字元開始截取字串create function fn_GetLastCharIndex(@Chars varchar(1000),@Char varchar(10))returns varchar(1000)begin declare @i int set @i=CharIndex(@Char,@Chars) while(@i>0) begin set @Chars=Substring(@Chars,@i+1,le
1.對查詢進行最佳化,應盡量避免全表掃描,首先應考慮在 where 及 order by 涉及的列上建立索引。 2.應盡量避免在 where 子句中對欄位進行 null 值判斷,否則將導致引擎放棄使用索引而進行全表掃描,如:select id from t where num is null可以在num上設定預設值0,確保表中num列沒有null值,然後這樣查詢:select id from t where num=03.應盡量避免在 where