
在SQL语句中,CREATE DATABASE 语句用于创建数据库。
具体用法如下:
示例:
下面的 SQL 语句创建一个名为 “my_db” 的数据库:
-from 树懒学堂
数据库表可以通过 CREATE TABLE 语句来添加。
1、打开Microsoft SQL Server 2012,选中需要查询所有表的数据库。
2、选中需要查询的表后,点击左上角的“新建查询”,如图。
3、点击“新建查询”后,会在右边d出一个编辑框,我们需要在这里编写sql语句,来查询该数据库下的所有表结构。
4、编写sql语句,点击“执行”,当然,这表语句我们可以根据实际情况,来改变条件只查询需要的表名。
5、这时,会在右下方出现最终的查询结果,name即该库下所有的表名。
我的是SQL2005的哦、你看看、、use master
go--创建“商品信息数据库”数据库、
if exists(select from sysobjects where name='商品信息数据库')
drop database 商品信息数据库
go
create database 商品信息数据库
on primary
(
name='商品信息数据库',
filename='D:\商品信息数据库mdf',
size=10MB,
maxsize=50MB,
filegrowth=2MB
)
log on
(
name='商品信息日志'
filename='D:\商品信息日志ldf',
size=5MB,
maxsize=25MB,
filegrowth=1MB)
go
use master
go--创建“Sales”数据库、
if exists(select from sysobjects where name='Sales')
drop database Sales
go
create database Sales
on primary
(
name='Sales_Data',
filename='D:\Sales_Datamdf',
size=20MB,
maxsize=50MB,
filegrowth=5%
),FILEGROUP fg1
( name=Sales_Data2,
filename='D:\Sales_Data2ldf',
size=20MB,
maxsize=50MB,
filegrowth=5MB )
log on
(
name='Sales_Log',
filename='D:\Sales_Logldf',
size=10MB,
maxsize=50MB,
filegrowth=5MB
)
go--删除数据库前面已经写出、 没运行过、有问题再Call我吧、祝你好运、、
首先要检查你的表与表之间是不是有约束(主外键约束),如果存在,才可以像 上面这位朋友的方式进行连接,一般连接有左连接、右连接、内连接,下面给你举例:
----做笛卡尔积
select sid,sname,scid,scsname,scscore from infom s ,score sc
------内连接 写法一
select sid,sname,scid,scsname,scscore
from infom s ,score sc inner join score sc
on sid= scid ------内连接的条件
------on sid <>scid --------是全集 - 交集
------where scscore>80
------内连接 方法二
select sid,sname,scid,scsname,scscore
from infom s ,score sc
where sid= scid
------
-------------------------------------------------------外连接 左连接
--------------左表数据完全显示,右表中相同的数据显示,不同数据null
select Studentname,scorescore
from Student left join score -----------------先写的为左表
on Studentid=score id -----------------连接条件
-------------------------------------------------------外连接 右连接
--------------右表数据完全显示,左表中相同的数据显示,不同数据显示null
select Studentname,scorescore
from Student right join score
on Studentid=score id
-------------------------------------------------------全连接 full join
-------------------------------------------------------左、右表的数据完全显示,相同的数据显示一次
select Studentname,scorescore
from Student full join score
on Studentid=score id
-------------------------------------------------------交叉联接
------------------------------------------交叉联接得到的是两表联接所有的数据组合
------------------------------------------(A表的数据记录 B 表的数据记录)
-------------------------------------------方式一
select Student,score from Student,score
-------------------------------------------方式二
select score ,Student from Student
cross join score
-----------------------------------------------------多表联接
--------------------------------------要求查出张三 C#的考试成绩,涉及student,score,subject三个表
---------方式一:
select studentname,subjectsname ,score score
from Student
inner join score
on studentid= scoreid
inner join subject
on scoreid=subjectid
where Studentname='张三' and subjectsname='C#'
---------方式二:等值联接
select studentname,subjectsname ,score score
from Student,score ,subject
where StudentDBid=scoreid and score id=subjectid
and Studentname='张三' and subjectsname='C#'
用一个TextBox控件
然后声明一个变量来接收
public string sql;
sql=thistextbox1text;
SqlConnection con=new Sqlconneciton("server=;uid=sa;pwd=123456;database=数据库的名称")
SqlCommand cmd=conCreateCommand();
cmdCommandText=sql;
cmdExecuteNonQuery();
select max(id) from 表 where num=100;--查最大ID
select from 表 where id =(select max(id) from 表 where num=100) and num=100;--查id最大并且num为100的那条数据
SQL SELECT 语句
SELECT 语句用于从表中选取数据。
结果被存储在一个结果表中(称为结果集)。
SQL SELECT 语法
SELECT 列名称 FROM 表名称
以及:
SELECT FROM 表名称
注释:SQL 语句对大小写不敏感。SELECT 等效于 select。
以上就是关于如何用SQL语句创建数据库全部的内容,包括:如何用SQL语句创建数据库、怎样用SQL语句查询一个数据库中的所有表、SQL使用查询分析器创建数据库等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)