1、先打开数据库管理平台【SQL Server Management Studio】连接好数据库系统。
2、鼠标点击【新建查询】,进入编写代码的窗口。
3、编写代码如下,*/size = 4,/*指定的大小,可以根据自己需要修改大小。
4、点击【执行】,下方消息出现【命令已成功完成。】说明没有出现问题。代码正确。
5、好了,建立完成。刷新查看数据库【st】是否成功。
oracle:create table myTestTable as
select rownum as id,
to_char(sysdate + rownum/24/3600, 'yyyy-mm-dd hh24:mi:ss') as inc_datetime,
trunc(dbms_random.value(0, 100)) as random_id,
dbms_random.string('x', 20) random_string
from dual
connect by level <= 100000
SqlServer:
SqlConnectionStringBuilder scsb = new SqlConnectionStringBuilder()
scsb.DataSource = @"127.0.0.1\SQLEXPRESS"
scsb.InitialCatalog = "MyMoreRows"//数据库名称
scsb.IntegratedSecurity = true
int numOfTestRecords = 30000//要创建的行数
string insertstr = "INSERT INTO LoadTable(teststr1, teststr2, teststr3)" +//LoadTable表名
"VALUES(@teststr1, @teststr2, @teststr3)"
SqlParameter teststr1param = new SqlParameter("@teststr1", SqlDbType.NVarChar, 50)
SqlParameter teststr2param = new SqlParameter("@teststr2", SqlDbType.NVarChar, 50)
SqlParameter teststr3param = new SqlParameter("@teststr3", SqlDbType.NVarChar, 50)
using (SqlConnection conn = new SqlConnection(scsb.ToString()))
{
conn.Open()
SqlCommand comm = new SqlCommand()
comm.Connection = conn
comm.CommandText = insertstr
comm.Parameters.Add(teststr1param)
comm.Parameters.Add(teststr2param)
comm.Parameters.Add(teststr3param)
SqlTransaction tran = conn.BeginTransaction("testtran")
comm.Transaction = tran
try
{
for (int i = 0i <numOfTestRecordsi++)
{
teststr1param.Value = "Col1Test-" + i
teststr2param.Value = "Col2Test-" + i
teststr3param.Value = "Col3Test-" + i
comm.ExecuteNonQuery()
textBox1.AppendText(">" + i + "<")
}
tran.Commit()
}
catch (Exception ex)
{
tran.Rollback()
}
}
create dababase studenton (
name=student_data,
filename='d:\data\student_data.mdf',
size=12mb,
maxsize=unlimted,
filegrowth=10% )
log on (
name=student_log,
filename='d:\data\student_ldf',
size=2mb,
maxsize=5mb,
filegrowth=2mb )
建表一:
create table student(
s_number char(10),
s_name char(8),
sex char(2) default('男'),
age int,
polity char(4),
check(student.sex in('男','女')),
check(student.age between 10 and 100),
primary key(student.s_number)
)
建表二:
create table score(
s_number char(10),
数学 int,
化学 int,
英语 int,
语文 int,
foreign key (s_number) references student(s_number)
)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)