English 中文(简体)
快速SQL问题:在H2中创建带有主键的表的正确语法?
原标题:
  • 时间:2009-03-28 06:59:04
  •  标签:

I m currently starting a new Java application using the H2 database, but I have some confusion about basic SQL use for creating tables. How do I make a table of entries (strings) each with unique, auto-incrementing, non-null, integer primary keys? One of the most basic things to do, but I m not sure offhand what the correct way to do it with H2 is.

I blame these for my confusion (specifies more than one way of doing the same thing between different databases; can t figure the right way for H2, though): http://www.w3schools.com/Sql/sql_primarykey.asp http://www.w3schools.com/Sql/sql_autoincrement.asp

最佳回答

如果我正确阅读了H2文档,这应该可以工作:

CREATE TABLE MyTableName(PKFieldName IDENTITY PRIMARY KEY, StringFieldName VARCHAR(255))

基本上,你只需要将你的关键列声明为IDENTITY类型。

For IDENTITY type see: http://www.h2database.com/html/datatypes.html#identity_type
For CREATE TABLE syntax see: http://www.h2database.com/html/grammar.html#create_table

问题回答

暂无回答




相关问题
热门标签