【问题标题】:SAS - SQL Server - Set Identity_Insert ONSAS - SQL Server - 设置 Identity_Insert ON
【发布时间】:2015-07-06 13:29:01
【问题描述】:

我正在向 SQL 数据库中插入一个表,并且我的数据集中有一个 ID 列。要插入它,我需要将 identity_insert 设置为 on。如何设置identity_insertproc sql 中使用SAS?

proc sql;
    insert into db.app (id, name)
    select a.id a.name from work.test as a;
quit;

【问题讨论】:

    标签: sql sql-server sas proc-sql


    【解决方案1】:

    根据this SAS tech support note,您可以按以下方式进行操作:

    libname x odbc dsn=mssqlserver user=xxx password=yyy
    dbconinit='set IDENTITY_INSERT foo ON'
    dbconterm='set IDENTITY_INSERT foo OFF';
    
    proc append base=x.foo data=work.foo;
    run;
    

    这假设您需要实际设置id 变量。如果您希望它自动递增,您应该能够将 id 变量从插入语句中移除。

    【讨论】:

    • 我在查找问题时看到了这一点,但我不明白。 dbconinit 和 foo 占位符有什么用?
    • foo 是您的数据集。 dbconinit 不是占位符,它是 libname 语句上的设置 - 请注意缺少分号。它是用于告诉 SQL Server 在连接初始化时要做什么的说明(然后dbconterm 是关于终止的说明)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-13
    相关资源
    最近更新 更多