自动在MSSQL中填写表

时间:2014-01-08 15:51:09

标签: sql

我对SQL很新,我有一个练习,我必须填充一些表,每个表有15个条目。我桌子的ER模型在这里:https://drive.google.com/file/d/0B9Nv7FRWWX54dnRIUGNPR0U2WTg/edit?usp=sharing 这就是我创建表格的方式

    CREATE TABLE Suppliers
             (sid INTEGER ,
              sAFM REAL ,
              sname CHAR(10) ,
              sstreet CHAR(20),
              stel REAL,
              PRIMARY KEY (sid))
CREATE TABLE Product
            (pid INTEGER,
             pname CHAR(10),
             pdescription CHAR(20),
             pprice REAL,
             pleft REAL,
             sid INTEGER NOT NULL,
             PRIMARY KEY (pid),
             FOREIGN KEY (sid) REFERENCES Suppliers
                     ON DELETE CASCADE
                     ON UPDATE CASCADE)

CREATE TABLE Categories
             (ccid INTEGER,
              cdescription CHAR(20),
              pid INTEGER NOT NULL,
              PRIMARY KEY (ccid),
              FOREIGN KEY (pid) REFERENCES Product
                     ON DELETE CASCADE
                     ON UPDATE CASCADE )

CREATE TABLE Supply
             (ssid INTEGER ,
              sdate CHAR(8),
              squantity REAL,
              sid INTEGER NOT NULL,
              pid INTEGER UNIQUE,
              PRIMARY KEY (ssid),
              FOREIGN KEY (sid) REFERENCES Suppliers,
              FOREIGN KEY (pid) REFERENCES Product
                     ON DELETE CASCADE
                     ON UPDATE CASCADE)
CREATE TABLE Customers
             (cid INTEGER ,
              cname CHAR(10) ,
              cAFM  REAL ,
              cstreet CHAR(20),
              ctel REAL,
              PRIMARY KEY (cid))
CREATE TABLE Often_Customers
              (cid INTEGER NOT NULL,
               ccredit_limit REAL ,
               cremainder REAL 
               PRIMARY KEY (cid)
               FOREIGN KEY (cid) REFERENCES Customers)
CREATE TABLE Payments 
              (cdate CHAR(8) ,
               cammount REAL ,
               cid INTEGER NOT NULL,
               PRIMARY KEY (cid),
               FOREIGN KEY (cid) REFERENCES Often_Customers
                       ON DELETE CASCADE)
CREATE TABLE Places
              (gid INTEGER ,
               gname CHAR(10) ,
               gpopulation REAL ,
               sid INTEGER NOT NULL,
               cid INTEGER NOT NULL,
               PRIMARY KEY (gid),
               FOREIGN KEY (sid) REFERENCES Suppliers,
               FOREIGN KEY (cid) REFERENCES Customers
                           ON DELETE CASCADE
                           ON UPDATE CASCADE)
CREATE TABLE Orders 
             (oid INTEGER ,
              odate_order CHAR(8),
              odate_send  CHAR(8),
              cid INTEGER UNIQUE,
              pid INTEGER NOT NULL,
              PRIMARY KEY (oid),
              FOREIGN KEY (cid) REFERENCES Customers,
              FOREIGN KEY (pid) REFERENCES Product
                              ON DELETE CASCADE 
                              ON UPDATE CASCADE)    

有没有一种简单的方法可以做到这一点,而不是为每个表写入15个插入命令?

1 个答案:

答案 0 :(得分:0)

您共享的google云端硬盘链接需要登录,这不是一个好主意 在你的问题帖子

您可以插入一行,然后转到Ms Excel并将其粘贴到那里 然后将其展开为一系列以生成15行并直接复制剩余的14行

我假设您正尝试通过SQL Server

进行此操作