1. 如果用sql查詢10000條以上數據用什麼方法查詢
10000條,真的不算多.1千萬條的我都見過,那個查詢一般要跑2-3個小時.
直接用select就可以.如果嫌慢就加個索引.
2. sql文1次性添加10000條數據
declare@countint=1
while(@count<=10000)
begin
insertintoseinouvalues(@count,'','')
set@count=@count+1
end
另外,如果表定義的時候id已經自增長了,把除了id以外的欄位都列出來
declare@countint=1
while(@count<=10000)
begin
insertintoseinou(column1,column2)values('','')
set@count=@count+1
end
3. sql寫語句如何循環執行10000次
調用循環執行,例如:
declare@nint
set@n=0
begin
while@n<10000
set@n=@n+1
--這里運行您要執行的1萬次操作
--例如您提問中的那些動作查詢
end
4. 在線求怎麼在資料庫造1萬條數據的SQL語句!
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 al
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 = 0; i < numOfTestRecords; i++)
{
teststr1param.Value = "Col1Test-" + i;
teststr2param.Value = "Col2Test-" + i;
teststr3param.Value = "Col3Test-" + i;
comm.ExecuteNonQuery();
textBox1.AppendText(">" + i + "<");
}
tran.Commit();
}
catch (Exception ex)
{
tran.Rollback();
}
}
5. 怎樣用一條sql語句向資料庫中插入10000條記錄
只能用循環了,以下是php語法
for($i=0;$i<10001;$i++){
INSERT INTO TABLE();//這里式sql語句
}
6. SQL語句 如何讓數據10000查詢出來顯示為1萬或者一萬
雖然每條語句提取出來的都是25萬條數據,各種情況的差異卻是巨大的,特別是將運行前我們可以把SQL SERVER的statistics I/O狀態打開。 (1)select title,
7. sql語句查詢上萬條數據。
用NOT IN 是很慢的一種查詢方式。
試試用Join。
select a.*, 'N' as chk from pay a
where a.txn_dt = '20090110'
and txn_sta_cd = '6'
union
select * from (
select b.*, isnull(c.txn_user_id,'N') as chk
from pay b left outer join pay c
on b.txn_user_id = c.txn_user_id
and b.txn_dt = c.txn_dt
and b.txn_sta_cd = '7'
and c.txn_sta_cd = '6'
where b.txn_dt = '20090110' ) d
where d.chk = 'N'
=========================================
如果不行, 試試下面的
select a.*, 'N' as chk
from pay a
where a.txn_dt = '20090110'
and a.txn_sta_cd = '6'
union
select * from (
select b.*, isnull(c.txn_user_id,'N') as chk
from
(select * from pay
where txn_dt='20090110'
and txn_sta_cd = '7') b left outer join
(select * from pay
where txn_dt='20090110'
and txn_sta_cd = '7') c
on b.txn_user_id = c.txn_user_id) d
where d.chk = 'N'
強烈要求補分~~~!!!!!!!