目前我不知在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