alter 语句

 

--基本语法:select [字段列表] from [表名] :查询出该表的所有记录
select ClsId, clsName, cl sTeacher, cl sNumber
f rom
TbClass
--只查询若干字段
select Cl sName, clsTeacher from
TbClass
一一
如果就是想查看所有字段的,可以使用1*'代替字段列表
select * from TbClass
--[]的作用:避免字段名与关键字的冲突,但是绝对不要使用关键字当
--字段名或者表名
SELECT [cl sName],[clsTeacher] FROM [ TbClass ]

 --修改表结构和追加约束--

1.删除一-列
  alter  table TbStudent drop  column stuPhone
  --2.添加一一列
  alter table TbStudent add column stuPhone一-

3。修改字段的数据类型
  alter   table TbStudent alter column stuGender nchar (1 )
  --4.添加主键约束
  alter   table TbStudent add constraint PK TbStudent stuId primary key (stuId)
  --5.添加唯一性约束
  alter table TbStudent add constraint UK TbStudent stuName unique (s tuName)--6.添加check约束
 -- 6.添加check约束
  al ter  table  TbStudent add  constraint CK TbStudent stuAgecheck (stuAge>=18 and   stuAge<=35)
  --7.添加非空约束,实际上就是对列的数据类型修改
  alte r  table  TbStudent alter column  stuPhone char (11 )  not nul 1
  --8.添加外键约束
  alter  table  TbStudent add  constraint  FK TbStudent stuClassIdforeign key (stuClassId)  refe rences  TbClass (clsId)
  --9.外键的级联删除/更新
  语法:  on delete  [no  action | cascade ]
  on update [no action | cascade]
  alter  table  TbStudent add  constraint  FK TbStudent stuClassId
  foreign key (stuClassId)  references  TbClass (clsId)  O]n delete cascade
--10.删除约束
  alter table TbStudent drop constraint FK TbStudent stuClassId
  --11.一条语句删除多条约束
  alter table TbStudent drop constraint FK TbStudent stuClassId, CK TbStuden
  --12.一条语句添加多个约束
  alter table TbStudent add
  constraint  FK_ TbStudent_ stuClassId foreign key (stuClassId)  re ferences  Tb

constraint  FK_ TbStudent_ stuClassId foreign key (stuClassId)  re ferences  Tb

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值