1.插入單行資料
當列名列有預設值時,輸入 defaultinsert
[into
] 表名 [
(列名)
]values (值列表)
2.插入多行資料
將現有資料庫值插入到新資料庫中
方法1:
方法2:insert
into
《表名》
(列名)
---必須預先建立新的資料庫
select
《列名》
from
《源表名》
通過union關鍵字合併資料進行插入select
(列名)
---不用預先建立,語句執行時,自動建立
into
《表名》
---只能執行一次該語句
from
《源表名》
使用update更新資料行insert
into
《表名》
(列名)
select
《列名》
union
---該語句不允許使用預設值關鍵字
select
《列名》
union..
...select
《列名》
使用delete刪除資料update 表名 ---更新多列資料使用逗號隔開
set 列名=更新值 ---勿忘條件限制,以防有效資料的丟失
[where 更新條件]
使用truncate刪除資料行delete
from 表名 ---擁有外來鍵表對應值的主鍵表,想要刪除
[where 條件]
---要先刪除外來鍵表
使用select語句進行查詢truncate
table 表名 ---很少使用,刪除的資料不能恢復
使用as命名列(修改列名稱)select
《列名》
from
《表名》
[where
《查詢條件表示式》
]---asc(公升序,預設)desc(降序)
[order
by《排序的列名》
[asc
/desc
]]
字串鏈結select 源列名 as 自定義列名 ---定義多列,之間用逗號隔離
from 表名
查詢空行select 源列名1
+源列名2
as 自定義列名
from 表名 ---源列名必須為同種型別
---為字串時,後資料加到前資料
---為數字時,相加
查詢原有但被清除過的列select 列名
from 表名
[where 列名 is
null
]
限制固定行數select
'被刪除列名'
as 別名
from 表名
按照百分數返回行select
top3 列名 ---前3行
from 表名
select
top3
percent 列名 ---前百分之三
from 表名
Sql Server 基礎語法
1.新增乙個非空型別的字段,需要加預設值,否則會報錯 alter table demo1 dbo cities add testtime datetime not null default getdate getdate 獲取當前時間 2.修改列名 if exists select from sys...
SQL Server 增刪改查基礎
主鍵為自增時可不填寫 插入單條資料 insert into product values 008 原子筆 辦公用品 100,null,2019 11 11 insert into product select 008 原子筆 辦公用品 100,null,2019 11 11 插入多條資料 inser...
SQL Server 臨時表插入基礎語法
有關臨時表的資料插入 1 把臨時表中的資料插入到另乙個表中 insert into 表 select from temp 2 把乙個表中字段複製到臨時表中 select into temp from 表 where 3 本地臨時表的名稱以單個數字符號 打頭 它們僅對當前的使用者連線是可見的 4 當使...