表的基本操作

2021-09-29 23:25:08 字數 2440 閱讀 8896

3.primary key 約束

4.unique約束

foreign 約束

check 約束

default 約束

use teaching

gocreate table course

(cno char(4) primary key,

cname nvarchar(20) not null,

classhour tinyint ,

credit tinyint

)use teaching

goalter table student

alter column sname nvarchar(20) null

use teaching

goalter table student

add teacher nvarchar(10)

use teaching

goalter table student

drop column sage

use teaching

gocreate table sc

(sno char(7),

cno char(4),

score int,

constrauint ok_js primary key(sno,cno)–pk_js是約束名

)use student1

gocreate table 學生

(學號 char(6) not null,

姓名 nvarchar(8) not null,

身份證號 char(18),

性別 nchar(1) not null

)alter table 學生

add constraint pk_st primary key(學號)

alter table 學生

drop constraint pk_st

use student1

gocreate table 學生1

(學號 char(6) primary key,

姓名 nvarchar(8) not null,

身份證號 char(18) constraint uk_st unique,

性別 nchar(1) not null

)alter table 學生

drop constraint uk_st unique(身份證號)

alter table 學生1

drop constraint uk_st

use student1

gocreate table 成績

(學號 char(6) constraint f_st_pk foreign key references 學生(學號),

課程號 char(4),

成績 int

)第一種:

use teaching

goalter table sc

add constraint st_foreign foreign key(sno) references student(sno)

use teaching

goalter table 成績

drop constraint f_st-pk

use student1

gocreate table books

(book_id char(15) primary key,

book_name nvarchar(30) not null,

max_lvl tinyint not null check(max_lvl<=250)

)use student1

goalter table 成績

add constraint cj_constrait check(成績陳》=0 and成績<=100)

use student1

goalter table 成績

drop constraint cj_constraint

use student1

gocreate table st

(學號 char(6) not null,

姓名 nvarchar(10) not null,

專業名 nvarchar(20) null,

性別 nchar(1) not null,

出生日期 date not null,

總學分 tinyint null,

備註 ntext null,

入學日期 date default date(getdate())

)use student1

goalter table 學生

add 入學日期 date null

constraint df_date

default getdate()

use student1

goalter table 學生

drop constraint df_date

表的基本操作

建立表 create table table name 屬性名 資料型別,屬性名 資料型別,檢視表物件 describe table name desc 簡寫 檢視表的詳細定義 show create table table name 修改表 增1.在表的最後乙個位置增加字段 alter table...

順序表的基本操作 順序表基本操作上機實驗

理解線性結構的基本概念,掌握兩種基本的儲存結構 順序儲存結構 順序表 和鏈式儲存結構 單鏈表 用c語言實現在兩種儲存結構上的對應操作 包括建立 刪除插入元素 遍歷等 鞏固強化c程式設計的基本方法和能力。完成順序表的建立 元素刪除 遍歷等操作,具體內容如下 有序的一組整數 1,2,3,4,6 設計順序...

順序表的基本操作

include include include define error 1 define ok 1 typedef int status typedef int lelemtype typedef struct lnode lnode,linklist status creatlinklist l...