如何插入相同记录的行数? [英] how to insert number of rows same record?

查看:164
本文介绍了如何插入相同记录的行数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想要填写10条记录中的3列相同?

解决方案

SQL对包含重复相同数据的行不好 - 并且通常有如果你需要一遍又一遍地存储相同的数据,你的数据库或系统设计会出现问题。



如果你这样做是为了测试,为你提供样本数据然后这是一回事 - 但我仍然建议使用不同的数据(尝试 Lorem Ipsum [ ^ ]来源可读但无意义的数据)



否则,只需使用循环(假设您的行包含您未填写的标识列):

  DECLARE   @ I   INT  
SET @ I = 0 ;
WHILE @ I < 10
BEGIN
INSERT INTO MyTable(Model) VALUES ' 相同文字'
SET @I = @ I + 1
END


suppose 3 col in that col i want fill 10 record same?

解决方案

SQL Is not good with rows that contain the same data repeated - and there is normally a problem with your database or system design if you need to store the same data over and over again.

If you are doing this for testing to provide you with "sample data" then that is one thing - but I'd still suggest using different data (try Lorem Ipsum[^] for a source of "readble" but meaningless data)

Otherwise, just use a loop (provided your row contains an identity column you aren't filling in):

DECLARE @I INT
SET @I = 0;
WHILE @I < 10
BEGIN
   INSERT INTO MyTable (Model) VALUES('Same Text')
   SET @I = @I + 1
END


这篇关于如何插入相同记录的行数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆