目录
参考网址:https://www.w3school.com.cn/sql/sql_primarykey.asp
1.SQL Server 注释快捷键
注释:Ctrl+K、Ctrl+C (按住Ctrl,然后K、C)
取消注释:Ctrl+K、Ctrl+U(按住Ctrl,然后K、U)
2.数据库初始及建立工作
---------------------------数据库初始化工作(Database initialization exercise)--------------------------
--set nocount on
--set dateformat mdy
--go
--use master
--go
if exists (select * from sysdatabases where name='ChestnutCommunity')
drop database ChestnutCommunity
go
----------------------------数据库的建立(Establishment of the database)-----------------------------
CREATE database ChestnutCommunity
ON primary
(NAME = 'ChestnutCommunity_data',
FILENAME = 'D:\data\ChestnutCommunity_data.MDF' ,
SIZE = 2,
FILEGROWTH =1,
MAXSIZE=10)
LOG ON
(NAME = 'ChestnutCommunity_Log',
FILENAME = 'D:\data\ChestnutCommunity_Log.LDF' ,
SIZE = 1,
FILEGROWTH = 1,
MAXSIZE=5)
GO
删除数据库
if exists (select * from sysdatabases where name='ChestnutCommunity')
drop database ChestnutCommunity
go
3.建表
建表
----------------------------用户表(users)---------------------------------
use ChestnutCommunity
if exists (select * from sysobjects where name='users')
drop table users
go
create table users
(id varchar(11) not null,
passwords varchar(30) not null,
userName varchar(30) not null,
levels varchar(30) not null,
sex char(2) not null check(sex in('男','女')) default '男',
introduction varchar(200),
attention int not null,
fan int not null,
phoneNumber char(11) not null,
primary key(id)
)
go
删表
use ChestnutCommunity
if exists (select * from sysobjects where name='users')
drop table users
4.约束
4.1主键约束
PRIMARY KEY

本文介绍了SQL Server的常用操作,包括注释快捷键、数据库初始化、建表、各种约束的使用(主键、外键、check、unique、default)、数据的增删改查、创建视图以及触发器的创建和管理。
最低0.47元/天 解锁文章
1265

被折叠的 条评论
为什么被折叠?



