sqlserver建个数据库和表
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sqlserver建个数据库和表相关的知识,希望对你有一定的参考价值。
create database text;
use text;
create table text
(
ii int not null primary key auto_increment,
aa varchar(10),
bb text,
date datetime,
ss int #1 or 0
);
insert into forum text (null, 'aa','bb',now(),1);
以上是使用mysql建立的数据库和表,请问,使用SqlServer怎么用代码写以上的内容?就是在查询分析器中输入语句后,创建与以上mysql创建的同样的数据库和表,语句怎么写?
创建数据库,创建表,插入信息,尤其是那个自增该怎么写?
麻烦会的帮我写下,谢谢了~~~
go
use text
go
create table text
(
ii int not null Identity (1,1),
aa varchar(10),
bb text,
date datetime,
ss bit
);
自增列是Identity (1,1)
sqlserver 数据库表数据合并
--先把表1和表2的solver合并起来,再分别和表1,表2做连接With T
As
(
Select solver From 表1
union
Select solver From 表2
)
Select T.solver,Isnull(A.amount1,0) As amount1,isnull(B.amount2,0) As amount2 From T
Left Join 表1 A on T.solver=A.solver
Left Join 表2 B on T.solver=B.solver追问
As
(
Select solver From (查询语句1) A
union
Select solver From (查询语句2) B
)
Select T.solver,Isnull(A.amount1,0) As amount1,isnull(B.amount2,0) As amount2 From T
Left Join (查询语句1) A on T.solver=A.solver
Left Join (查询语句2) B on T.solver=B.solver
--你贴个图片也蛮郁闷的,直接把你的语句放进去就可以了,或者先放到临时表,在用刚才的查询,这是MSSQL哦,2005+版本
--以下也可以
Select T.solver,Isnull(A.amount1,0) As amount1,isnull(B.amount2,0) As amount2 From(
Select solver From (查询语句1) A
union
Select solver From (查询语句2) B
) T
Left Join (查询语句1) A on T.solver=A.solver
Left Join (查询语句2) B on T.solver=B.solver 参考技术A 先建好表三,然后执行sql语句:
insert into table3 values(select t1.solver,t1.amount1,t2.amount2 from table1 t1 inner join table2 t2 on t1.solver = t2.solver);
insert into table3 values(select t1.solver,t1.amount1,0 from table1 t1,table t2 where t1.solver <> t2.solver);
insert into table3 values(select t2.solver,0,t2.amount1 from table1 t1,table t2 where t1.solver <> t2.solver);追问
不建表三可以查询出来吗?
追答select t1.solver,t1.amount1,t2.amount2 from table1 t1 inner join table2 t2 on t1.solver = t2.solver
UNION
select t1.solver,t1.amount1,0 from table1 t1,table t2 where t1.solver t2.solver
UNION
select t2.solver,0,t2.amount1 from table1 t1,table t2 where t1.solver t2.solver
试试吧
以上是关于sqlserver建个数据库和表的主要内容,如果未能解决你的问题,请参考以下文章