Sql Server创建数据库和表
创建数据库
USE master
GO
CREATE DATABASE EmployeeSystem--创建员工管理系统数据库
on
(
NAME='EmployeeSystem_data',--主文件逻辑文件名
FILENAME='D:\员工管理系统\EmployeeSystem_data.mdf', --主文件文件名
SIZE=5mb,--系统默认创建的时候会给主文件分配初始大小
MAXSIZE=200MB,--主文件的最大值
filegrowth=5-- 主文件的增长幅度
)
LOG ON
(
name='EmployeeSystem_log',--日志文件逻辑文件名
filename='D:\员工管理系统\EmployeeSystem_log.ldf',--日志文件屋里文件名
SIZE=5MB,--日志文件初始大小
MAXSIZE=100MB,--主文件的最大值
filegrowth=2 --启动自动增长
)
go
创建表
use EmployeeSystem
go
create table EmployeeBaseData--创建员工基础资料表
(
EmployeeID int identity(1,1) not null,--员工ID号
EmployeeName varchar(15) not null,--员工姓名
Gender char(2) not null,--员工姓别
DateOfBirth date not null,--出生日期
CorporationID int not null,--所属公司ID号
constraint PK_EmployeeID primary key clustered(EmployeeID),--设置员工ID为主键,聚集索引
--constraint PK_struent primary key clustered(SNO,BookID) --设置多个主键,设置SNO,BookID为主键
constraint UQ_EmployeeName Unique NONClusterEd(EmployeeName),--设置员工姓名为唯一键,非聚集索引
constraint C_Gender Check (Gender in('男','女')),--约束
constraint FK_CorporationID Foreign key (CorporationID) References Corporation(CorporationID),--设置外键,关连Corporation(CorporationID),关连表的字段必须是主键或唯一键
)
go
/虽然问题已经提问蛮久了,但是刚好最近自己也遇到这个问题,就把自己的解决方法贴出来吧
这个是用C#写的,原理都是一样的。/
string kk = "tt,oo,pp"; //假设从文本框获取的值是字符串kk
string[] b = kk.Split(','); //将字符串中的","除去后存入数组里
string endstr = "";
for (int i = 0; i < b.Length; i++) //根据数组的元素个数判断循环次数
{
kk = "'" + b[i] + "'"; //在每个元素前后加上我们想要的格式,效果例如:
// " 'tt' "
if (i < b.Length - 1) //根据数组元素的个数来判断应该加多少个逗号
{
kk += ",";
}
endstr += kk;
}
string sqlstr = "select * from tablename where xxx in(" + endstr + ")";
//最后 select * from tablename where xxx in ('tt','oo','pp')
select top 10 word from [dbo].[English_WORD]
declare @s nvarchar(4000);
set @s = '';
select @s = @s + [word] + '-' from (select top 10 word from [dbo].[English_WORD]) as a
select @s;