USE [warehouse] GO /****** Object: Table [dbo].[库存] Script Date: 2023/5/30 9:34:18 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO CREATE TABLE [dbo].[库存]( [货物编号] [char](5) NOT NULL, [仓库编号] [char](5) NOT NULL, [库存量] [int] NULL, PRIMARY KEY CLUSTERED ( [货物编号] ASC, [仓库编号] ASC )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY] ) ON [PRIMARY] GO ALTER TABLE [dbo].[库存] ADD DEFAULT ((0)) FOR [库存量] GO ALTER TABLE [dbo].[库存] WITH CHECK ADD FOREIGN KEY([仓库编号]) REFERENCES [dbo].[仓库] ([仓库编号]) GO 如何分辨这个表中的主键和外键
时间: 2023-06-30 12:19:26 浏览: 117
这个表中的主键是由货物编号和仓库编号组成的联合主键,即 PRIMARY KEY CLUSTERED ( [货物编号] ASC, [仓库编号] ASC )。而外键是仓库编号,它引用了仓库表中的仓库编号字段,通过以下代码进行了添加约束:
```
ALTER TABLE [dbo].[库存] WITH CHECK ADD FOREIGN KEY([仓库编号]) REFERENCES [dbo].[仓库] ([仓库编号])
```
其中,WITH CHECK 用于指定在添加外键约束时检查是否所有的行都满足约束条件,如果不满足则不允许添加该约束。这样可以保证数据的完整性和一致性。
相关问题
root@zhaosai conf]# sqoop import --connect jdbc:mysql://192.168.160.130:3306/mydb --username root -P --table news --hive-import --hive-table mydb.news --incremental append --check-column id --last-value 0 --split-by id --target-dir /hdfs://zhaosai:9000/user/hive/warehouse/news --num-mappers 1 23/06/07 17:23:56 INFO sqoop.Sqoop: Running Sqoop version: 1.4.7 Enter password: 23/06/07 17:24:04 INFO tool.BaseSqoopTool: Using Hive-specific delimiters for output. You can override 23/06/07 17:24:04 INFO tool.BaseSqoopTool: delimiters with --fields-terminated-by, etc. 23/06/07 17:24:04 INFO manager.MySQLManager: Preparing to use a MySQL streaming resultset. 23/06/07 17:24:04 INFO tool.CodeGenTool: Beginning code generation Loading class `com.mysql.jdbc.Driver'. This is deprecated. The new driver class is `com.mysql.cj.jdbc.Driver'. The driver is automatically registered via the SPI and manual loading of the driver class is generally unnecessary. 23/06/07 17:24:04 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `news` AS t LIMIT 1 23/06/07 17:24:04 INFO manager.SqlManager: Executing SQL statement: SELECT t.* FROM `news` AS t LIMIT 1 23/06/07 17:24:04 INFO orm.CompilationManager: HADOOP_MAPRED_HOME is /opt/programs/hadoop-2.7.6 注: /tmp/sqoop-root/compile/b07035b094b6ac39b87f2ef11261c934/news.java使用或覆盖了已过时的 API。 注: 有关详细信息, 请使用 -Xlint:deprecation 重新编译。 23/06/07 17:24:05 INFO orm.CompilationManager: Writing jar file: /tmp/sqoop-root/compile/b07035b094b6ac39b87f2ef11261c934/news.jar 23/06/07 17:24:05 INFO tool.ImportTool: Maximal id query for free form incremental import: SELECT MAX(`id`) FROM `news` 23/06/07 17:24:05 ERROR tool.ImportTool: Import failed: java.io.IOException: java.sql.SQLSyntaxErrorException: Unknown column 'id' in 'field list' at org.apache.sqoop.tool.ImportTool.initIncrementalConstraints(ImportTool.java:322) at org.apache.sqoop.tool.ImportTool.importTable(ImportTool.java:511) at org.apache.sqoop.tool.ImportTool.run(ImportTool.java:628) at org.apache.sqoop.Sqoop.run(Sqoop.java:147) at org.apache.hadoop.util.ToolRunner.run(ToolRunner.java:70) at org.apache.sqoop.Sqoop.runSqoop(Sqoop.java:183) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:234) at org.apache.sqoop.Sqoop.runTool(Sqoop.java:243) at org.apache.sqoop.Sqoop.main(Sqoop.java:252) Caused by: java.sql.SQLSyntaxErrorException: Unknown column 'id' in 'field list' at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:120) at com.mysql.cj.jdbc.exceptions.SQLError.createSQLException(SQLError.java:97) at com.mysql.cj.jdbc.exceptions.SQLExceptionsMapping.translateException(SQLExceptionsMapping.java:122) at com.mysql.cj.jdbc.StatementImpl.executeQuery(StatementImpl.java:1200) at org.apache.sqoop.tool.ImportTool.getMaxColumnId(ImportTool.java:238) at org.apache.sqoop.tool.ImportTool.initIncrementalConstraints(ImportTool.java:309)
根据你提供的信息,这是一个使用Sqoop从MySQL导入数据到Hive的命令。但是,在执行命令时出现了错误。错误信息是“Unknown column 'id' in 'field list'”,意思是在字段列表中找不到名为“id”的列。这可能是因为在MySQL表中不存在“id”列,或者“id”列的名称不正确。您需要检查MySQL表中是否存在该列,并确保在Sqoop命令中正确指定了列名。
for file_str in files_str_list: if '.hive-staging_hive' in file_str: continue rexp = re.search("(/user/hive/warehouse/.*)", file_str) if rexp: file = rexp.group(1) files.append(file) return files
这段代码是对获取到的文件列表(files_str_list)进行遍历,判断每个文件字符串(file_str)是否包含`.hive-staging_hive`,如果包含则跳过该文件。然后使用正则表达式匹配出符合要求的文件路径(`/user/hive/warehouse/`开头的路径),并将其加入文件列表(files)中。最终返回的是符合要求的文件列表(files)。
阅读全文