如何在sql server 2005中建表

如题所述

选中数据库下的表右击,在出现的对话框最上方有新建表选项,新出现的对话框中有列名、数据类型、允许Null值三列,这里可以添加表的的列,添加好列后保存Ctrl+S或者点击上方的保存,填写表名称确定就创建好了。

二、使用SQL语句创建数据表

use StuDB --使用某个数据库(在某个数据库下建表)
go
if exists(select * from sysobjects where name='stuMarks')--查询数据库是否已存在此表
drop table stuMarks--如果存在该表则删除,不存在不执行此句
create table stuMarks --stuMarks是表的名称
(
ExamNo int identity(1,1) primary key,--列名 数据类型 约束
stuNo char(6) not null,--列名 数据类型 是否允许插入Null值
writtenExam int not null,
LabExam int not null
)
go

-- 其中,列属性"identity(起始值,递增量)" 表示"ExamNo"列为自动编号, 也称为标识列alter table 表名
add constraint 约束名 约束类型 具体的约束说明
alter table 表名
drop constraint 约束名
温馨提示:答案为网友推荐,仅供参考
第1个回答  2016-08-22
一、可以可视化操作
选中数据库下的表右击,在出现的对话框最上方有新建表选项,新出现的对话框中有列名、数据类型、允许Null值三列,这里可以添加表的的列,添加好列后保存Ctrl+S或者点击上方的保存,填写表名称确定就创建好了。

二、使用SQL语句创建数据表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

use StuDB --使用某个数据库(在某个数据库下建表)
go
if exists(select * from sysobjects where name='stuMarks')--查询数据库是否已存在此表
drop table stuMarks--如果存在该表则删除,不存在不执行此句
create table stuMarks --stuMarks是表的名称
(
ExamNo int identity(1,1) primary key,--列名 数据类型 约束
stuNo char(6) not null,--列名 数据类型 是否允许插入Null值
writtenExam int not null,
LabExam int not null
)
go

-- 其中,列属性"identity(起始值,递增量)" 表示"ExamNo"列为自动编号, 也称为标识列alter table 表名
add constraint 约束名 约束类型 具体的约束说明
alter table 表名
drop constraint 约束名
相似回答