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

SQL Server數(shù)據(jù)庫表格操作方法詳解

 更新時(shí)間:2024年10月02日 10:53:05   作者:_Csharp  
SQL Server是一種關(guān)系型數(shù)據(jù)庫管理系統(tǒng),常用于存儲(chǔ)和管理大量的數(shù)據(jù),在SQL Server中數(shù)據(jù)以表格的形式存儲(chǔ),這篇文章主要介紹了SQL Server數(shù)據(jù)庫表格操作方法的相關(guān)資料,需要的朋友可以參考下

表格的創(chuàng)建

代碼操作

-- StudentTwo 庫名
use StudentTwo
go

-- table 表-- database 數(shù)據(jù)庫 存放表-- 先判斷表是否存在,如果存在先刪除再創(chuàng)建
-- sysobjects 表-- 判斷所有系統(tǒng)表有沒有一個(gè)表名字為number,如果有刪除掉
if exists(select * from sysobjects where name = 'nunber')
drop table number --刪除掉
go

create table XueShengTable(
	-- 學(xué)生ID 整形誰 identity 標(biāo)識(shí)符作用從1000開始 每次遞增1 ,以后添加學(xué)生信息時(shí)候不要標(biāo)識(shí)列添加
	StudentId int identity(1000,1),

	-- 姓名
	StudentName varchar(20) not null,

	-- 性別
	Gender char(2) not null,
)
注意: 列后面不加 not null,加null是當(dāng)前列可為空,加not null是當(dāng)前列不可為空

界面操作

點(diǎn)擊數(shù)據(jù)庫 --> 點(diǎn)開使用的數(shù)據(jù)看 --> 右鍵擊表 --> 新建表

增刪改查

解釋:

-- 插入、增加學(xué)生

-- insert into 表名(列名) values(值)

-- 向哪個(gè)表中插入那一列對應(yīng)值是什么

-- 注意: 列名之間使用逗號(hào)隔開,值和列名一一對應(yīng),類型也得匹配

寫法1:

insert into XueShengTable(StudentName,Gender,Binrthday,Age,Phone,StudentAddress,ClassId,StudentCard) values('迪迦','男','2000-09-18',14,'15377300008','河南省南陽市鄧州市',2341,12345678910987)

寫法2:

-- 也可以將列名省略

insert into XueShengTable values('凹凸曼','男','2000-09-18',12345678910987,23,'15377300008','河南省南陽市鄧州市',1)

-- 語法

delete from 表名 where 條件

方法1delete: 

-- 把學(xué)號(hào)1001數(shù)據(jù)刪除

delete from XueShengTable where StudentId = 1001

-- 第二種刪除方案 truncate:

truncate table XueShengTable -- 刪除整個(gè)表格

-- 小提示: delete刪除的時(shí)候比truncate刪除的更快 -- delete刪除的時(shí)候 不允許這條記錄被外鍵引用,可以先把外鍵的關(guān)系刪除掉,再進(jìn)行刪除這條數(shù)據(jù) -- truncate 要求刪除的表不能有外鍵的約束

-- 語法:

updaste 表名 set 列名 = 值, 列名 = 值 where 條件

--修改學(xué)號(hào)為1000學(xué)生的姓名改為李白,出生年月

update XueShengTable set StudentName = '李白',Binrthday='1975-01-01' where StudentId=1000

-- 查詢所有信息 類似于數(shù)組遍歷

select * from XueShengTable

-- 查詢具體列的數(shù)據(jù)查詢姓名這一列 select 列名, from 表名 select StudentName,Gender from XueShengTable

-- 條件查詢 : 查詢年齡等于23的 select 列名, 列名 from 表名 where Age = 23

select StudentName from XueShengTable where Age = 23

-- 查詢滿足條件的所有列

select * from XueShengTable where Age <= 23

--邏輯運(yùn)算符號(hào) and 并且關(guān)系 相當(dāng)于&&,or或者條件 相當(dāng)于||;

select * from XueShengTable where Age>14 and Age<23

總結(jié)

到此這篇關(guān)于SQL Server數(shù)據(jù)庫表格操作方法的文章就介紹到這了,更多相關(guān)SQL Server表格詳解內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論