【正文】
S Where AGE >= 60 SQL 的數(shù)據(jù)控制 例 50 授予 LILI 有對(duì)表 STUDENTS 的查詢(xún)權(quán)。其中 Insert 、 Update 、 Delete 、 Select 、 REFERENCES 、 TRIGGER 有對(duì)表做相應(yīng)操作的權(quán)限,故稱(chēng)為表特權(quán)。 select id = 39。 打印字符串 39。 else print 39。 stockname like 39。 ([]指定值的范圍 ) stockname like 39。 or stocknumber 1000 and stockindex = 24 not stock*** = 39。, 39。) 運(yùn)行結(jié)果如下 { {abc} [abc]*/ REPLICATE() 函數(shù)返回一個(gè)重復(fù) character_expression 指定次數(shù)的字符串 以下是引用片段: select replicate(39。, 2) 運(yùn)行結(jié)果如下 19 abcabcabc NULL*/ REVERSE() 函數(shù)將指定的 字符串的字符排列順序顛倒 REPLACE() 函數(shù)返回被替換了指定子串的字符串 /*select replace(39。, 39。, 39。]) 函數(shù)返回 數(shù)據(jù)庫(kù) 的編號(hào) DB_NAME(database_id) 函數(shù)返回?cái)?shù)據(jù)庫(kù)的名稱(chēng) HOST_ID() 函數(shù)返回 服務(wù)器 端計(jì)算機(jī)的名稱(chēng) HOST_NAME() 函數(shù)返回服務(wù)器端計(jì)算機(jī)的名稱(chēng) IDENTITY([, seed increment]) [AS column_name]) IDENTITY() 函數(shù)只在 SELECT INTO 語(yǔ)句中使用用于插入一個(gè) identity column 列到新表中 21 以下是引用片段: /*select identity(int, 1, 1) as column_name into newtable from oldtable*/ ISDATE() 函數(shù)判斷所給定的表達(dá)式是否為合 理日期 ISNULL(, ) 函數(shù)將表達(dá)式中的 NULL 值用指定值替換 ISNUMERIC() 函數(shù)判斷所給定的表達(dá)式是否為合理的數(shù)值 NEWID() 函數(shù)返回一個(gè) UNIQUEIDENTIFIER 類(lèi)型的數(shù)值 NULLIF(, ) NULLIF 函數(shù)在 expression1 與 expression2 相等時(shí)返回 NULL 值若不相等時(shí)則返回 expression1 的值 MS SQL 的一些經(jīng)典常用操作語(yǔ)句匯總 : Select * From TableName Order By CustomerName Collate Chinese_PRC_Stroke_ci_as : select encrypt(39。) select pwdpare(39。) = 1相同;否則不相同 encrypt(39。) select pwdpare(39。) = 1相同;否則不相同 : declare list varchar(1000),sql nvarchar(1000) select list=list 39。 set sql=39。 exec (sql) : EXEC master..xp_fixeddrives A,B 表是否相等 : if (select checksum_agg(binary_checksum(*)) from A) 22 = (select checksum_agg(binary_checksum(*)) from B) print 39。 : DECLARE hcforeach CURSOR GLOBAL FOR SELECT 39。,N39。 : 開(kāi)頭到 N 條記錄 Select Top N * From 表 N 到 M 條記錄 (要有主索引 ID) Select Top MN * From 表 Where ID in (Select Top M ID From 表 ) Order by ID Desc N 到結(jié)尾記錄 Select Top N * From 表 Order by ID Desc : sp_renamedb 39。 9:獲取當(dāng)前數(shù)據(jù)庫(kù)中的所有用戶表 select Name from sysobjects where xtype=39。) 11:查看與某一個(gè)表相關(guān)的視圖、存儲(chǔ)過(guò)程、函數(shù) select a.* from sysobjects a, sysments b where = and like 39。 13:查詢(xún)用戶創(chuàng)建的所有數(shù)據(jù)庫(kù) select * from master..sysdatabases D where sid not in(select sid from master..syslogins where name=39。 [n].[標(biāo)題 ]: Select * From TableName Order By CustomerName [n].[標(biāo)題 ]: Select * From TableName Order By CustomerName sql中的保留字 action add aggregate all alter after and as asc avg avg_row_length auto_increment between bigint bit binary blob bool both by cascade case char character change check checksum column columns ment constraint create cross current_date current_time current_timestamp data database databases date datetime day day_hour day_minute day_second dayofmonth dayofweek dayofyear dec decimal default delayed delay_key_write delete desc describe distinct distinctrow double drop end else escape escaped enclosed enum explain exists fields file first float float4 float8 flush foreign from for full function global grant grants group having heap high_priority hour hour_minute hour_second hosts identified ignore in index infile inner insert insert_id int integer interval int1 int2 int3 int4 int8 into if is isam join key keys kill last_insert_id leading left length like lines limit load local lock logs long longblob longtext low_priority max max_rows match mediumblob mediumtext mediumint middleint min_rows minute minute_second modify month monthname myisam natural numeric no not null on optimize option optionally or order outer outfile pack_keys partial password precision primary procedure process processlist privileges read real references reload regexp rename replace restrict returns revoke rlike row rows second select set show shutdown smallint soname sql_big_tables sql_big_selects sql_low_priority_updates sql_log_off sql_log_update sql_select_limit sql_small_result sql_big_result sql_warnings straight_join starting status string table tables temporary terminated text then time timestamp tinyblob tinytext tinyint trailing to type use using unique unlock unsigned update usage values varchar variables varying varbinary with write when where year year_mo