Constraints Archives - {coding}Sight https://codingsight.com/category/database-development/constraints/ Blog for SQL Server DBAs and Developers Mon, 08 Aug 2022 16:10:34 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 https://codingsight.com/wp-content/uploads/2021/10/cropped-Soсial_-Fb_180х180-1-32x32.png Constraints Archives - {coding}Sight https://codingsight.com/category/database-development/constraints/ 32 32 How to Create a Table with Multiple Foreign Keys and Not Get Confused https://codingsight.com/how-to-create-table-with-multiple-foreign-keys-and-not-get-confused/ Fri, 28 May 2021 06:52:24 +0000 http://codingsight.com/?p=14272 Understanding Table Relations SQL server adds foreign keys to implement relations between tables in a relational database. A table can have one-to-one, one-to-many, or many-to-many relations with another table, depending upon the type of data you want to store. A one-to-one relationship is simple and rarely used. Each record in a particular table relates to …

The post How to Create a Table with Multiple Foreign Keys and Not Get Confused appeared first on {coding}Sight.

]]>
SQL FOREIGN KEY CONSTRAINT: The Ultimate, Easy Guide for Newbies https://codingsight.com/sql-foreign-key-the-ultimate-easy-guide-for-newbies/ Fri, 26 Mar 2021 11:06:30 +0000 http://codingsight.com/?p=12525 Newbie? Then an SQL foreign key may be foreign to you. You may have heard different opinions about SQL foreign keys. If you haven’t, soon you will. Or your experience will affect your view. The main thing to know is, foreign keys are a must in relational databases. Yet, some developers may remove or ignore …

The post SQL FOREIGN KEY CONSTRAINT: The Ultimate, Easy Guide for Newbies appeared first on {coding}Sight.

]]>
The Difference Between Primary Key And Unique Key https://codingsight.com/the-difference-between-primary-key-and-unique-key/ Wed, 03 Apr 2019 20:28:32 +0000 https://codingsight.com/?p=6593 “What is the difference between a primary key constraint and a unique key constraint?” This is probably the most frequently-asked job interview question for database developers. In this article, we will try to answer it. Let’s start by looking at what primary and unique keys are, as well as at their similarities. Primary Key A …

The post The Difference Between Primary Key And Unique Key appeared first on {coding}Sight.

]]>
SQL Server Bulk Insert – Part 2 https://codingsight.com/sql-server-bulk-insert-part-2/ Thu, 21 Feb 2019 08:09:54 +0000 https://codingsight.com/?p=6256 In the previous part of this article, we discussed how to import CSV files to SQL Server with the help of BULK INSERT statement. We discussed the main methodology of bulk insert process and also the details of BATCHSIZE and MAXERRORS options in scenarios.  In this part, we will go through some other options (FIRE_TRIGGERS, …

The post SQL Server Bulk Insert – Part 2 appeared first on {coding}Sight.

]]>
Difference Between Inline and Out-of-Line Constraints https://codingsight.com/difference-between-inline-and-out-of-line-constraints/ Tue, 15 May 2018 11:52:19 +0000 http://codingsight.com/?p=4071 Constraints on tables and columns allow you to enforce the data quality. In SQL, there are two ways of creating constraints on a table: inline and out of line. In this article, I am going to explore these constraints and the advantages they have, as well as explain which one I recommend and why. What is …

The post Difference Between Inline and Out-of-Line Constraints appeared first on {coding}Sight.

]]>
Counting references to a record in a table via Foreign Keys https://codingsight.com/counting-the-number-of-references-to-a-record-in-a-table-via-foreign-keys/ Tue, 05 Sep 2017 06:27:31 +0000 http://codingsight.com/?p=2156 I have recently needed to solve the task for my own purpose: to calculate the number of external records linked by a foreign key for each record in a table (File). The task was solved for the specific structure of the File table, but if necessary, the solution can be reworked to a universal one. …

The post Counting references to a record in a table via Foreign Keys appeared first on {coding}Sight.

]]>
Insight into SQL Server Unique Constraints https://codingsight.com/insight-into-sql-server-unique-constraints/ Thu, 23 Mar 2017 09:05:56 +0000 http://codingsight.com/?p=890 What are unique key constraints? A unique constraint is a rule that restricts column entries to unique. In other words, this type of constraints prevents inserting duplicates into a column. A unique constraint is one of the instruments to enforce data integrity in an SQL Server database. Since a table can have only one primary …

The post Insight into SQL Server Unique Constraints appeared first on {coding}Sight.

]]>
CHECK Constraints in SQL Server https://codingsight.com/check-constraints-in-sql-server/ Fri, 27 Jan 2017 13:29:09 +0000 http://codingsight.com/?p=413 In this article, we will talk about CHECK constraints. We will see how to add CHECK constraints to SQL Server table columns and discuss the pitfalls you may encounter when using this type of SQL Server constraints. CHECK constraint basics CHECK constraints are simply conditional statements (predicates that return TRUE or FALSE) that refer to …

The post CHECK Constraints in SQL Server appeared first on {coding}Sight.

]]>