SQL Server-数据库常用基础知识

创建数据库:

create database 数据库名

go

create database NewsDB
go

在数据库中创建表:

USE 数据库名

go

create table 表名

(

)

go

create database NewsDB
go
use NewsDB
go
create table NewsType
(
tid int identity(1,1) primary key , --编号
tName varchar(50) unique,           --类型名称
)
go

 identity(初始值,递增量)

五种常见约束:

1.主键约束:Primary Key

nid int primary key identity(1,1),   --新闻编号

 2.唯一约束:unique

stuName varchar(50)unique not null,      --姓名

 3.默认约束:Default

stuSex char(2) default('男') not null,

 4.外键约束;references

tid int references NewsType (tid),   --新闻类型

 5.检查约束:check

stuscore int  check (stuscore>0 and stuscore<100)  not null,  --分数

 <>不等于,

!非,

!>不大于,

!<不小于,

and 与,

or 或,

not 非

查询数据: 

select * from 表名【where 条件语句】

*代表所有列名  查询全部

select * from NewsInfo where nTitle='科比'

添加数据: 

insert into 表名 (列名)values <值>

insert into student (stuName,stuSex,stuscore)values ('张三','男','12')

 修改数据:

update 表名  set  列名  ='张三'【where 条件语句】

update student set stuscore='90'where stuSex='男'

 删除数据:

Delete from 表名  where <条件语句>

Delete from 表名      删除所有

delete from student where stuSex='女'

 

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

飞鹰@四海

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值