Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9183855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:54:21+00:00 2026-06-17T18:54:21+00:00

I currently have: CREATE TABLE galleries_gallery ( id INT NOT NULL PRIMARY KEY IDENTITY,

  • 0

I currently have:

CREATE TABLE  galleries_gallery (
    id              INT NOT NULL PRIMARY KEY IDENTITY,
    title           NVARCHAR(50) UNIQUE NOT NULL,
    description     VARCHAR(256),
    templateID      INT NOT NULL REFERENCES galleries_templates(id),
    jsAltImgID      INT NOT NULL REFERENCES libraryImage(id)
    jsAltText       NVARCHAR(500),
    dateCreated     SMALLDATETIME NOT NULL,
    dateUpdated     SMALLDATETIME NOT NULL,
    lastUpdatedBy   INT,
    deleted         BIT NOT NULL DEFAULT 0
);

But this adds constraints with auto generated names which make it hard to drop the constraint later. What do I need to add in order to name the constraints?

The above example is SQL Server and I also need it in PostgreSQL.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T18:54:22+00:00Added an answer on June 17, 2026 at 6:54 pm

    In SQL Server, you can use the constraint keyword to define foreign keys inline and name them at the same time.

    Here’s the updated script:

    CREATE TABLE  galleries_gallery (
        id              INT NOT NULL PRIMARY KEY IDENTITY,
        title           NVARCHAR(50) UNIQUE NOT NULL,
        description     VARCHAR(256),
        templateID      INT NOT NULL 
            CONSTRAINT FK_galerry_template 
            REFERENCES galleries_templates(id),
        jsAltImgID      INT NOT NULL 
            CONSTRAINT FK_gallery_jsAltImg
            REFERENCES libraryImage(id)
        jsAltText       NVARCHAR(500),
        dateCreated     SMALLDATETIME NOT NULL,
        dateUpdated     SMALLDATETIME NOT NULL,
        lastUpdatedBy   INT,
        deleted         BIT NOT NULL DEFAULT 0
    );
    

    I just made a test and apparently the same thing also works in PostgreSQL: http://www.sqlfiddle.com/#!12/2ae29

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have this schema: CREATE TABLE `users` ( `users_id` int(11) NOT NULL AUTO_INCREMENT,
I currently have a table like this: Stuff ---------- StuffId identity int not null
I currently have a parent table: CREATE TABLE members ( member_id SERIAL NOT NULL,
I currently have database setup like so: CREATE TABLE `article` ( `id` int(11) NOT
I have the following table in SQL Server: CREATE TABLE [dbo].[Users]( [Id] [int] IDENTITY(1,1)
Assuming you have the following database table: create table Names ( Id INT IDENTITY
I have two tables called Reviews and Levels. CREATE TABLE [dbo].[Reviews]( [ReviewID] [int] IDENTITY(1,1)
Currently I have this table in my database: CREATE TABLE `twMCUserDB` ( `id` int(11)
Currently I have around 900,000 entries in the data_article_key_terms table to associate key terms
I have one mysql table 'alfa' that will contain the primary key of another

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.