dfcq

1.数据库管理工具

工具创建数据库

1>登录数据库管理工具【Microsoft SQL Server Management Studio】

 

2>右键【新建数据库】

 

 

3>数据数据库名称,点击确定,就建立好了一个【MyDB】的数据库

 

创建数据表

 

 

代码创建数据库,以及数据表

 

 代码创建数据库

use master--用系统数据库
go
if exists(select * from sys.sysdatabases where name=\'MyDB\')--查询MyDB数据库是否存在
begin
  select \'该数据已经存在\'
  drop database myDB--如果存在MyDB数据库则drop掉数据库
  end
else--如果不存在
begin 
 create database MyDB
 on primary
 (
 name=\'MyDB\',
 filename=\'C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyDB.mdf\',
 size=5mb,
 maxsize=100mb,
 filegrowth=15%
 )
log on
(
name=\'MyDB_log\',
 filename=\'C:\Program Files (x86)\Microsoft SQL Server\MSSQL10_50.MSSQLSERVER\MSSQL\DATA\MyDB_log.mdf\',
 size=5mb,
 maxsize=20mb,
 filegrowth=15%
)
end

 

 代码创建数据表

use MyDB
go
if exists(select * from sys.sysobjects where name=\'Users\')
begin
     select \'该表已经存在\'
     drop table Users
end
else
begin
create table Users
(
    Id int not null identity(1,1) primary key,
    UserName nvarchar(50) not null,
)
end

简单的查询语句

下图数数据表Users的数据值

 

下图是各种简单的查询语句的使用

use MyDB
select * from Users
--where
select * from Users where Id=1
--不等于,!=或者<>
select * from Users where Id != 2
select * from Users where Id <> 2
--or
select * from Users where Id=1 or UserName=\'bol\'
--and
select * from Users where Id=1 and UserName=\'col\'

--like \'%a%\'前后模糊查询,只要字母中包含o就行
select * from Users where UserName like \'%o%\'

--‘%o’前模糊,只要以a开头就行,后面的不管
select * from Users where UserName like \'a%\'

--‘o%’后模糊,只要以l结尾就行,前面不管
select * from Users where UserName like \'%l\'

--not,除了以a开头的,其他啥都行
select * from Users where UserName not like \'a%\'
--in,一次请求几个数据
select * from Users where Id in(1,2,3)
View Code

 

分类:

技术点:

相关文章:

  • 2021-08-16
  • 2018-03-20
  • 2018-03-26
  • 2021-08-22
  • 2021-06-23
猜你喜欢
  • 2022-01-02
  • 2021-10-27
  • 2021-11-08
  • 2021-11-23
  • 2021-08-05
  • 2022-02-04
  • 2022-12-23
相关资源
相似解决方案