欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

淺析SQL數(shù)據(jù)操作語句

 更新時間:2015年11月04日 10:01:07   作者:淚灑星辰  
本文給大家收集整理了些關(guān)于sql數(shù)據(jù)操作語句的相關(guān)資料,介紹的非常詳細,具有參考借鑒價值,特此分享在腳本之家網(wǎng)站供大家參考

SQL 中的運算符

 1算術(shù)運算符:

+:加運算,求兩個數(shù)或表達式想加的和
-:減運算,求兩個數(shù)或表達式相減的差
*,乘運算,求兩個數(shù)或表達式相乘的積
/:除運算,求兩個數(shù)或表達式相除的商
%:取模運算,求兩個數(shù)或表達式相除的余數(shù)

2.賦值運算

=:把一個數(shù)或表達式賦值給另一個標(biāo)量.

3.比較運算符

=:等于   >大于   < 小于    <>不等于   >= 大于等于   <=小于等于    !=不等于

4.邏輯運算符

AND :當(dāng)且僅當(dāng)兩個布爾表達式為true時,返回true
OR:當(dāng)且僅當(dāng)兩個布爾表達式都為false時,返回false
NOT對布爾表達式的值取反,優(yōu)先級別最高

      使用T-SQL插入數(shù)據(jù)

1切換數(shù)據(jù)庫,以Myschool為例

Use myschool

2.查詢表中的數(shù)據(jù)(*號代表表中所有的列)

select * from student

      新增數(shù)據(jù)到student表中

01如果要新增全部列,表名后可以不寫列名,但是要提供所有列的值

02如果只想給一張表中添加部分列,那么在表名后要跟上列名,并且需要保證除了你給出的列的值之外其他列都允許為空

加入數(shù)據(jù)到student這張表中student括號后跟的是列名如果列名中有自增列,一定要把自增列刪了.

values括號后更的是每一列所對應(yīng)的值

注意:每一列對應(yīng)一個值

insert into student(StudenttNo, LoginPwd, StudentName, Gender, Gradeld, Phone, Address, Birthday, Email)
values (23214,5634,'淚灑星辰',0,2,5434,'北京市','2015-10-31 09:29:59','lsfjkl')

當(dāng)student表中有一列為默認值是在values值中一定要加入default

eg:

假如studentName有個默認值則在studentName對應(yīng)的值為default

insert into student(StudenttNo, LoginPwd, StudentName, Gender, Gradeld, Phone, Address, Birthday, Email)
values (23214,5634,default,0,2,5434,'北京市','2015-10-31 09:29:59','lsfjkl')

      一次向一張表中插入多條數(shù)據(jù)(有三種方案)

方案一:(studentbak)這是一個不存在的表,方案一就相當(dāng)于把表(student必須存在)表備份一份studentbak

select * into studentbak
from student

方案二:student(目標(biāo)表)studentbak(已存在的表)就相當(dāng)于把studentbak表中的數(shù)據(jù)附加到student表中
--*代表所有的列如果目標(biāo)表中有自增列,你附加上去會報錯,你必須studentbak表中把*號改成具體的每一列,把自增列刪除

eg:

insert into student
select * from studentbak

         方案三:如果要新增全部列,表名后可以不寫列名,但是要提供所有列的值

如果只想給一張表中添加部分列,那么在表名后要跟上列名,并且需要保證除了你給出的列的值之外其他列都允許為空

eg:

insert into student
select '何' 
        

                             修改表中的數(shù)據(jù)

update,見到update一定要加where條件(where后的限定條件不能用=和null做對比,必須使用is null)
update后跟表名,set后跟列名,如果有多個列名用逗號分開
where 為限定條件,只修改id=192ABC的那一行數(shù)據(jù)的studentNo何studentName兩列

eg:

update student set studentNo=1,StudentName='淚灑星辰'
where ID='192ABC' 

                          delete刪除表中的數(shù)據(jù)(刪除數(shù)據(jù)的時候會記錄日志,id編號不會從1開始)

見到delete一定要加where條件(where后的限定條件不能用=和null做對比,必須使用is null)
delete后跟表名
where后跟的是限定條件,只刪除id為192ABC的這一行

eg:

delete student
where ID='192ABC'

                    truncate刪除表中的數(shù)據(jù)(刪除數(shù)據(jù)的時候不會記錄日志徹底刪除,id編號會從1重新開始)

truncate后不需要跟where條件

下面抽點時間給大家介紹Android中使用SQL語句操作數(shù)據(jù)庫

數(shù)據(jù)的增加

1、創(chuàng)建一個SQLite數(shù)據(jù)的幫助類

SQLiteDatabase db = helper.getWritableDatabase();

2、執(zhí)行SQL語句,實現(xiàn)數(shù)據(jù)的增加

db.execSQL("insert into person (name,number) values (?,?)", new Object[] { name, number });

3、關(guān)閉數(shù)據(jù)庫

db.close();

數(shù)據(jù)的刪除

1、創(chuàng)建一個SQLite數(shù)據(jù)的幫助類

SQLiteDatabase db = helper.getWritableDatabase();

2、執(zhí)行SQL語句,實現(xiàn)數(shù)據(jù)的修改

db.execSQL("delete from person where name=?", new Object[] { name });

3、關(guān)閉數(shù)據(jù)庫

db.close();

數(shù)據(jù)的修改

1、創(chuàng)建一個SQLite數(shù)據(jù)的幫助類

SQLiteDatabase db = helper.getWritableDatabase();

2、執(zhí)行SQL語句,實現(xiàn)數(shù)據(jù)的修改

db.execSQL("update person set number=? where name=?", new Object[] { newnumber, name });

3、關(guān)閉數(shù)據(jù)庫

db.close();

數(shù)據(jù)的查詢

1、創(chuàng)建一個SQLite數(shù)據(jù)的幫助類

SQLiteDatabase db = helper.getReadableDatabase();

2、調(diào)用SQLite數(shù)據(jù)庫的幫助類中的rawQuery方法查詢數(shù)據(jù)

Cursor cursor = db.rawQuery("select * from person where name=?", new String[] { name });

3、查詢數(shù)據(jù)庫中所有的數(shù)據(jù)

boolean result = cursor.moveToNext();

4、關(guān)閉游標(biāo)工程

cursor.close();

5、關(guān)閉數(shù)據(jù)庫

db.close();

6、返回數(shù)據(jù)庫中是否存在需要查詢的結(jié)果

return result;

相關(guān)文章

最新評論