SQL Server 數(shù)據(jù)庫基本操作語句總結(jié)建站知識
導(dǎo)讀:1建站知識SQL Server 數(shù)據(jù)庫基本操作語句總結(jié),需要的朋友可以參考一下網(wǎng)站建設(shè)網(wǎng)站seo優(yōu)化課程。
復(fù)制代碼 代碼如下:
--sql基本操作
--創(chuàng)建數(shù)據(jù)庫
create database Studets
--創(chuàng)建表
create table student ( sno char(5), sname char(20), ssex char(2), sage smallint, sdept char(15) )
create table course ( cno char(3), cname char(30), cpno char(3), ccredit smallint )
create table sc ( sno char(5), cno char(3), grade int )
--查看表信息
select * from student select sno as 學(xué)號 from student select * from course select * from sc
--修改表
--插入列
alter table student add scome datetime
--修改列的字段類型 alter table student alter column scome char(50)
--刪除 --刪除列
alter table student drop column scome
--刪除表 drop table student drop table course drop table sc
--完整性約束實(shí)現(xiàn)
--sno 非空唯一,ssex檢查約束, sage默認(rèn)大小
create table student ( sno char(5) not null unique, sname char(20), sex char(2), sage smallint default 20, sdept char(15), constraint sex check(sex in('男','女')), )
--刪除表的約束 alter table student drop constraint ssex
--添加字段約束 alter table student add constraint ssex check(sex in('男','女'))
--添加主鍵約束 alter table student add constraint PK_SNO primary key(sno) create table course ( cno char(3) not null unique, cname char(30), cpno char(3), ccredit smallint )
--關(guān)聯(lián)表主鍵已經(jīng)存在,可以如下操作添加主鍵和外鍵約束
alter table course add constraint PK_CNO primary key(cno), constraint FK_CPNO foreign key(cpno) REFERENCES sc(cno)
create table sc
(
sno char(5) foreign key references student(sno),
cno char(3) foreign key references course(cno),
grade int,
constraint PK_SC primary key(sno,cno)
)
ALTER TABLE [dbo].[sc] DROP CONSTRAINT [FK__sc__sno__0F975522]
ALTER TABLE [dbo].[sc] DROP CONSTRAINT [PK_SC]
ALTER TABLE [dbo].[sc] DROP CONSTRAINT [PK_SC]
--創(chuàng)建sc后,通過如下修改主外鍵
alter table sc add constraint PK_SC primary key(sno,cno),
constraint FK_SNO foreign key(sno) references student(sno),
constraint FK_CNO foreign key(cno) references course(cno)
--創(chuàng)建索引。
分為聚簇索引(clustered物理順序)和非聚簇索引(nonclustered邏輯順序,可多個)
復(fù)制代碼 代碼如下:
--not null約束字段時候。會創(chuàng)建一個系統(tǒng)內(nèi)置的約束鍵值,并且這種非空判斷,通過索引查詢實(shí)現(xiàn) --的,索引默認(rèn)創(chuàng)建一個系統(tǒng)索引
create unique index STUsno
on student(sno)
create unique index COUcno
on course(cno)
create unique index SCno
on sc(sno asc,cno desc)
聲明: 本文由我的SEOUC技術(shù)文章主頁發(fā)布于:2023-05-24 ,文章SQL Server 數(shù)據(jù)庫基本操作語句總結(jié)建站知識主要講述語句,操作,SQL網(wǎng)站建設(shè)源碼以及服務(wù)器配置搭建相關(guān)技術(shù)文章。轉(zhuǎn)載請保留鏈接: http://www.bifwcx.com/article/web_6278.html
為你推薦與SQL Server 數(shù)據(jù)庫基本操作語句總結(jié)建站知識相關(guān)的文章
-
通王TWCMS 2.0.3網(wǎng)站模板程序下載
(126)人喜歡 2024-01-15 -
Windows官方原版在哪里下載
(175)人喜歡 2024-01-15 -
WordPress網(wǎng)站模板發(fā)帖標(biāo)題顏色設(shè)置
(131)人喜歡 2024-01-07 -
修改discuz論壇帖子標(biāo)題80字符的長度限制
(249)人喜歡 2024-01-07 -
wordpress程序調(diào)用不帶超鏈接的Tag標(biāo)簽
(234)人喜歡 2024-01-05 -
網(wǎng)站在不同時期需調(diào)整內(nèi)容更新的方向
(112)人喜歡 2023-08-12