SQL Server 增刪改查基礎

2021-09-03 01:10:09 字數 1198 閱讀 4657

主鍵為自增時可不填寫

--插入單條資料

--① insert into product values('008','原子筆','辦公用品',100,null,'2019-11-11');

--② insert into product select '008','原子筆','辦公用品',100,null,'2019-11-11';

--插入多條資料

--① insert into product values('008','原子筆','辦公用品',100,null,'2019-11-11'),

('009','鉛筆','辦公用品',50,null,'2019-11-11');

--② insert into product select '008','原子筆','辦公用品',100,null,'2019-11-11' union

select '009','鉛筆','辦公用品',50,null,'2019-11-11' ;

--複製資料

insert into product (列名) select 《列名》 from (select * from product)--將查詢出的資料插入表中

updata product set product_name='筆芯',sale_price=10 where product_id = '008';
--根據條件刪除

delete from product where product_id = '001'

--清空表資料,初始化表

truncate table product

--查詢語法: select 《列名1>,《列名2>... from 《表名》

--查詢整張表資料

select * from product; --* 預設顯示全部列

--條件查詢

select * from product where product_type ='衣服'

查詢語句是sql語言中應用最多的部分,上述只是最基礎的查詢語句,複雜的還涉及到排序,分組,聚合,子查詢,多表查詢等等。

SQL Server基礎語法 增刪改查

1.插入單行資料insert into 表名 列名 values 值列表 當列名列有預設值時,輸入 default 2.插入多行資料 將現有資料庫值插入到新資料庫中 方法1 insert into 表名 列名 必須預先建立新的資料庫 select 列名 from 源表名 方法2 select 列名 ...

Sql server 實現增刪改查

vs2008 c sql server csharp view plain copy using system.data.sqlclient csharp view plain copy sqlconnection conn csharp view plain copy 連線資料庫 private ...

Sqlserver 增刪改查 改

我們就以院系,班級,學生來舉例。create table dbo yuanxi id int identity 1,1 not null,學校id 自增量 yuanxiname varchar 50 null,院系名字 create table dbo class id int identity 1...