centos7 sql server 创建数据库_表和删除

目前我不知在centos如何表名(百度好多也未找到,我暂时用Navicat Premium工具验证表名成功) 如果大佬知道,评论一下,Thank you

下载:Navicat Premium链接:https://pan.baidu.com/s/1BTYVF4cZe9TH_YN3Q7wZog
提取码:np5d
连接方法
在这里插入图片描述
在这里插入图片描述
登陆sqlserver

sqlcmd -S 127.0.0.1 -U SA -P '123456.com'

创建数据库 create database
use master ##创建数据失败需要先切换到master中

create database db1
go
create database db2
go

在这里插入图片描述

切换到db1数据库

 use [数据库名]

查看数据库
select name from sys.databases
go

 use db1
 go

创建表

create table [表名] 
(
 id int not null identity(1,1) primary key,  #设置为主键和自增长列,起始值为1,每次自增1
 name varchar(20) not null,   #默认不为空
)
create table biao1
(
 id int not null identity(1,1) primary key,
 name varchar(20) not null,
)
 go
 
 create table biao2
 (
 id int not null identity(1,1) primary key,
 name varchar(20) not null,
)
 go
 
create table biao3
 (
 id int not null identity(1,1) primary key,
 name varchar(20) not null,
 )
 go

添加数据

insert into [数据库名].dbo.[表名] ([列名1],[列名1]) values ('列名数据1','列名数据1')
insert into db1.dbo.biao1 (id,name) values ('1','xiaozhan')
go


 insert into db1.dbo.biao1 (id,name) values ('2','zhaoliying')
 go


insert into db1.dbo.biao1 (id,name) values ('3','luhan')
 go

查看数据

select * from [数据库名].dbo.[表名]
select * from db1.dbo.biao1
 go
select * from db1.dbo.biao1 where id='1'  ##查看一条数据
go

更新数据
update [数据库名].dbo.[表名] set [列名]=‘更新后的数据’ where [列名]=‘更新列数据’

 update db1.dbo.biao1 set name='yangmi' where id='1'
 go

删除数据
delete from [数据库名].dbo.[表名] where [列名]=‘更新列数据’

 delete from db1.dbo.biao1 where id='3'
 go

删除表
drop table [表名]

drop table biao3
go

删除数据库
drop database[数据库名]

drop database db2
go

问题解决:
问题1:有时候会删除数据库失败需要切换一下master
use master
drop database db2
go

问题2:提示这个错误

需要关闭模式,就可以了
在这里插入图片描述

再次执行删除

drop database db2
go
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值