
如在php中
<?php
//声明mysql连接标识符mysql_connect("mysql主机地址","用户名","密码")
$Conn1 = mysql_connect("192.168.1.110","root1","root1pwd")
$Conn2 = mysql_connect("192.168.1.112","root2","root2pwd")
//查询1
$SQL1 = "select * from YourTable1 "
$_r_s1 = mysql_query($SQL1, $Conn1)
//查询2
$SQL2 = "select * from YourTable2 "
$_r_s2 = mysql_query($SQL2, $Conn2)
//在每次查询中,对应的连接标识符$Conn1,$Conn2不能出错,否则会得到不一样的结果或者根本就无法运行啦。
?>
以serversql为例:if exists(select * from sysobjects where name='DepartmentTab')
drop table DepartmentTab
create table DepartmentTab--创建一个表
(
DepartID int primary key identity(1,1),--identity自增 ,primary key主键
DepartName nvarchar(50) unique,--unique唯一的,并且不能为空
condition int default('0') --default 默认为0
)
1、把主键定义为自动增长标识符类型在mysql中,如果把表的主键设为auto_increment类型,数据库就会自动为主键赋值。例如:
create
table
customers(id
int
auto_increment
primary
key
notnull,
name
varchar(15))
insert
into
customers(name)
values("name1"),("name2")
一旦把id设为auto_increment类型,mysql数据库会自动按递增的方式为主键赋值。
在MS
SQLServer中,如果把表的主键设为identity类型,数据库就会自动为主键赋值。例如:
create
table
customers(id
int
identity(1,1)
primary
key
notnull,
name
varchar(15))
insert
into
customers(name)
values("name1"),("name2")
select
id
from
customers
查询结果和mysql的一样。由此可见,一旦把id设为identity类型,MSSQLServer数据库会自动按递增的方式为主键赋
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)