表的建立和使用

2021-10-06 12:34:15 字數 1990 閱讀 9975

本次程式設計任務是:

在右側編輯區 create table 下的 begin-end 區域補全**,建立 student 、 course 和 score 三個表;

在右側編輯區 insert 下的 begin-end 區域補全**,向 score 表中插入下面給出的資料;

在右側編輯區 alt student table 下的 begin-end 區域補全**,修改 student 表結構,新增一列 addr 用於描述位址資訊,並設定資料型別以及長度為 varchar(256),;

在右側編輯區 del score table 下的 begin-end 區域補全**,刪除 score 表。

use studentdb

goset nocount on

go–********** create table

begin **********–

create table student

(sno varchar(50),

name varchar(50),

*** varchar(10),

birthday date,

discipline varchar(50),

school varchar(100)

);create table course

(cno varchar(50),

cname varchar(50),

description varchar(256),

credit float,

cinstitution varchar(128)

);create table score

(sno varchar(50),

cno varchar(50),

grade float

);–********** end **********–

goselect name, length, collation from syscolumns where id=object_id(『student』)

goselect name, length, collation from syscolumns where id=object_id(『course』)

goselect name, length, collation from syscolumns where id=object_id(『score』)

go–********** insert

begin **********–

insert into score values(『09011101』,101,89),

(『09011101』,102,78)

–********** end **********–

select * from score

go–********** alt student table

begin **********–

alter table student

add addr varchar(256)

–********** end **********–

goselect name, length, collation from syscolumns where id=object_id(『student』)

go–********** del score table

begin **********–

drop table score

–********** end **********–

gogo

if not exists(select 1 from sysobjects where name=『score』) --查詢表是否存在

begin

print 『not exists table score』

endgo

Sql Server建立和使用臨時表

建立臨時表 方法一 create table 臨時表名 欄位1 約束條件,欄位2 約束條件,create table 臨時表名 欄位1 約束條件,欄位2 約束條件,方法二 select into 臨時表名 from 你的表 select into 臨時表名 from 你的表 注 以上的 代表區域性臨...

SQL Server建立和使用臨時表

建立臨時表 方法一 create table 臨時表名 字段 1 約束條件,字段 2 約束條件 create table 臨時表名 字段 1 約束條件,字段 2 約束條件 方法二 select into 臨時表名 from 你的表 select into 臨時表名 from 你的表 注 以上的 代表...

表的建立和維護

表的建立和維護 修改表的約束條件 1.增加商品名稱不能為空 alter table goods modify goodsname not null 2.增加身份證不能重複 alter table customer add constraint card unique cardid 3.增加客戶的住址...