SQL 的 增刪改查 語句
SQL常用語句一覽(1)數據記錄篩選:sql="select*from數據表where字段名=字段值orderby字段名[desc]"sql="select*from數據表where字段名like'%字段值%'orderby字段名[desc]"sql="selecttop10*from數據表where字段名orderby字段名[desc]"sql="select*from數據表where字段名in('值1','值2','值3')"sql="select*from數據表where字段名between值1and值2"(2)更新數據記錄:sql="update數據表set字段名=字段值where條件表達式"sql="update數據表set字段1=值1,字段2=值2……字段n=值nwhere條件表達式"(3)刪除數據記錄:sql="deletefrom數據表where條件表達式"sql="deletefrom數據表"(將數據表所有記錄刪除)(4)添加數據記錄:sql="insertinto數據表(字段1,字段2,字段3…)values(值1,值2,值3…)"sql="insertinto目標數據表select*from源數據表"(把源數據表的記錄添加到目標數據表)。
SQL 的 增刪改查 語句
SQL常用語句一覽
(1)數據記錄篩選:
sql="select*from數據表where字段名=字段值orderby字段名[desc]"
sql="select*from數據表where字段名like'%字段值%'orderby字段名[desc]"
sql="selecttop10*from數據表where字段名orderby字段名[desc]"
sql="select*from數據表where字段名in('值1','值2','值3')"
sql="select*from數據表where字段名between值1and值2"
(2)更新數據記錄:
sql="update數據表set字段名=字段值where條件表達式"
sql="update數據表set字段1=值1,字段2=值2……字段n=值nwhere條件表達式"
(3)刪除數據記錄:
sql="deletefrom數據表where條件表達式"
sql="deletefrom數據表"(將數據表所有記錄刪除)
(4)添加數據記錄:
sql="insertinto數據表(字段1,字段2,字段3…)values(值1,值2,值3…)"
sql="insertinto目標數據表select*from源數據表"(把源數據表的記錄添加到目標數據表)
數據庫的增刪改查
1、數據庫增加數據: 1)插入單行 insert [into] <表名> (列名) values (列值) 例:insert into t_table (name,sex,birthday) values ('開心朋朋','男','1980/6/15') 2)將現有表數據添加到一個已有表 insert into <已有的新表> (列名) select <原表列名> from <原表名> 例:insert into t_table ('姓名','地址','電子郵件') select name,address,email from t_table 3)直接拿現有表數據創建一個新表并填充 select <新建表列名> into <新建表名> from <源表名>例:select name,address,email into t_table from strde 2、數據庫刪除數據: 1)刪除<滿足條件的>行delete from <表名> [where <刪除條件>]。
例:delete from t_table where name='開心朋朋'(刪除表t_table中列值為開心朋朋的行) 2)刪除整個表 truncate table <表名> truncate table tongxunlu 注意:刪除表的所有行,但表的結構、列、約束、索引等不會被刪除;不能用語有外建約束引用的表3、數據庫修改數據 update <表名> set <列名=更新值> [where <更新條件>] 例:update t_table set age=18 where name='藍色小名' 4、數據庫查詢數據: 1)精確(條件)查詢select <列名> from <表名> [where <查詢條件表達試>] [order by <排序的列名>[asc或desc]] 2)查詢所有數據行和列。例:select * from a 說明:查詢a表中所有行和列 3)使用like進行模糊查詢 注意:like運算副只用于字符串,所以僅與char和varchar數據類型聯合使用例:select * from a where name like '趙%' 說明:查詢顯示表a中,name字段第一個字為趙的記錄 4)使用between在某個范圍內進行查詢 例:select * from a where nianling between 18 and 20 說明:查詢顯示表a中nianling在18到20之間的記錄 5)使用in在列舉值內進行查詢 例:select name from a where address in ('北京','上海','唐山') 說明:查詢表a中address值為北京或者上海或者唐山的記錄,顯示name字段 擴展資料: 插入之前需要創建數據表,創建方式如下: CREATE TABLE 表名稱(列名稱1 數據類型,列名稱2 數據類型,列名稱3 數據類型,。
.) 例如:--流程步驟定義表 create table T_flow_step_def( Step_no int not null, --流程步驟ID Step_name varchar(30) not null, --流程步驟名稱 Step_des varchar(64) not null, --流程步驟描述 Limit_time int not null, --時限 URL varchar(64) not null, --二級菜單鏈接 Remark varchar(256) not null, ) 參考資料:百度百科-sql語句大全。
數據庫增刪改查語句怎么寫
首先,不同數據庫管理系統的SQL語句不同,
再次,sqlserver的語句是這樣的:
增:
INSERT INTOTableNameVALUES('列值',‘列值’, ,‘列值’)
刪:
DELETE FROM TableName
WHERESomeCondition;
改:
UPDATETableName
SET ColumnName = 列值
WHERESomeCondition;
查:SELECT ' 列值',‘列值’, ,‘列值’
FROM 表名
WHERE 條件;
數據庫管理系統語法大同小異
用SQL語句隨便寫一條數據庫增刪改查語句
表名: person
字段: id, name, age
1 張三 20
2 李四 22
3 王五 23
查詢: select id,name,age from person;
刪除: delete from person where id=1 (刪除ID=1的那條數據,)
delete from person (刪除person表中的所有數據);
修改: update person set name="劉德華" where id=2; (就會李四的名字改成劉德華);
增加: insert into person values(4,'趙六',24);
我想學習數據庫增刪改查
增:insert into 表名(列1,列2。)
values (值1,值2。.)刪:delete from 表名 (刪除表里面的所有記錄) delete from 表名 where 條件 (帶條件刪除,可以有多個條件)改:update 表名 set 列=新值 (修改一個字段) update 表名 set 列=新值,列=新值。
(修改多個字段) update 表名 set 列=新值 where 條件 (同上,帶條件更新表)查: select * from 表名 (查所有記錄) select * from 表名 where 條件 (查帶有條件的所有記錄) select 列1,列2 。from 表名 (查某幾列,可以是一列) select 列1,列2。
. from 表名 where 條件 (帶條件查某些列) 還有很多細節,不是一句兩句能說清楚的,自己去找本數據庫的書看看吧,在應用中會有很多需求要改變的,祝你好運。
sql語句的增刪改查
4、說明:創建新表
create table tabname(col1 type1 [not null] [primary key],col2 type2 [not null],..)
根據已有的表創建新表:
A:create table tab_new like tab_old (使用舊表創建新表)
B:create table tab_new as select col1,col2… from tab_old definition only
5、說明:刪除新表
drop table tabname
6、說明:增加一個列
Alter table tabname add column col type
注:列增加后將不能刪除。DB2中列加上后數據類型也不能改變,唯一能改變的是增加varchar類型的長度。
7、說明:添加主鍵: Alter table tabname add primary key(col)
說明:刪除主鍵: Alter table tabname drop primary key(col)
8、說明:創建索引:create [unique] index idxname on tabname(col….)
刪除索引:drop index idxname on tabname
注:索引是不可更改的,想更改必須刪除重新建。
9、說明:創建視圖:create view viewname as select statement
刪除視圖:drop view viewname
10、說明:幾個簡單的基本的sql語句
選擇:select * from table1 where 范圍
插入:insert into table1(field1,field2) values(value1,value2)
刪除:delete from table1 where 范圍
更新:update table1 set field1=value1 where 范圍
查找:select * from table1 where field1 like '%value1%' (所有包含'value1'這個模式的字符串)---like的語法很精妙,查資料!
排序:select * from table1 order by field1,field2 [desc]
總數:select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1[separator]
sql數據庫--存儲過程增刪改查四個語句
1. SQL SELECT DISTINCT 語句:在表中,可能會包含重復值。這并不成問題,不過,有時您也許希望僅僅列出不同(distinct)的值。
關鍵詞 DISTINCT 用于返回唯一不同的值。
2. INSERT INTO 語句:INSERT INTO 語句用于向表格中插入新的行。
3. Update 語句:Update 語句用于修改表中的數據。
4. DELETE 語句:DELETE 語句用于刪除表中的行。
轉載請注明出處華閱文章網 » 數據庫的增刪改查語句