About 958,000 results
Open links in new tab
  1. How do I create a foreign key in SQL Server? - Stack Overflow

    I have never "hand-coded" object creation code for SQL Server and foreign key decleration is seemingly different between SQL Server and Postgres. Here is my sql so far: drop table exams; drop table

  2. Adding named foreign key constraints in a SQL Create statement

    Nov 9, 2016 · 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:

  3. How to CREATE tables with foreign keys POSTGRESQL

    Apr 23, 2020 · I want to CREATE 4 tables that has FOREIGN KEYS of each other. table students : CREATE TABLE students ( PRIMARY KEY (student_id), student_id SERIAL, student_name …

  4. How can I add a foreign key when creating a new table?

    Oct 27, 2008 · The answer to your question is almost the same as the answer to this one . You need to specify in the table containing the foreign key the name of the table containing the primary key, and …

  5. Create a one to many relationship using SQL Server

    Aug 20, 2009 · Define a column in Table A as having a Foreign key relationship based on the primary key of Table B This means that Table A can have one or more records relating to a single record in …

  6. sql - Create table with multiple Foreign Keys - Stack Overflow

    Aug 12, 2023 · Alternatively (and this would be my definite preference), create a supertype table called Item and make Book and Video subtype tables to it, enforced with a foreign key:

  7. SQL Server Different ways of creating table with foreign key

    Dec 25, 2017 · I need to create table with a foreign key. So far I have been doing that like this: CREATE TABLE books ( book_id NVARCHAR (15) NOT NULL UNIQUE, author_id INT REFERENCES …

  8. Creating a composite foreign key in SQL Server 2008

    Jan 30, 2017 · The columns in the Primary Table do not match a primary key or unique constraint. There can be many records in the secondary table with the same Key1 and Key2 so we made the primary …

  9. Foreign key referencing a 2 columns primary key in SQL Server

    Jul 5, 2010 · This question is pretty much similar to this one, but for SQL Server 2005 : I have 2 tables in my database: --'#' denotes the primary key [Libraries] #ID #Application Name 1 MyApp ...

  10. sql - Foreign Key to non-primary key - Stack Overflow

    Aug 26, 2013 · I have a table which holds data, and one of those rows needs to exist in another table. So, I want a foreign key to maintain referential integrity. CREATE TABLE table1 ( ID INT NOT NULL …