[SQLAlchemy]创建:主键索引唯⼀约束联合唯⼀约束联合主键约束1. 主键
from sqlalchemy import*
test = Table(
'test', metadata,
Column('id', BigInteger, primary_key=True)
)
2. 索引
from sqlalchemy import*
test = Table(
'test', metadata,
Column('id', BigInteger, index=True)
)
3. 唯⼀约束
创建唯一约束sql语句from sqlalchemy import*
test = Table(
'test', metadata,
Column('id', BigInteger, unique=True)
)
4. 联合唯⼀约束
from sqlalchemy import*
test = Table(
'test', metadata,
Column('id', BigInteger, primary=True),
Column('col1', String(20)),
Column('col2', Numeric(20,4)),
UniqueConstraint('col1','col2', name='idx_col1_col2')
)
5. 联合主键约束
⽅法⼀:
from sqlalchemy import*
test = Table(
'test', metadata,
Column('id', BigInteger),
Column('col1', String(20)),
PrimaryKeyConstraint('id','col1', name='idx_id_col1')
)
⽅法⼆:
from sqlalchemy import*
test = Table(
'test', metadata,
Column('id', BigInteger, primary_key=True),
Column('col1', String(20), primary_key=True),
)
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论