Home
Search results “Oracle foreign keys indexed”
Oracle SQL Tutorial 21 - How to Create / Drop Indexes
 
03:58
In the last video, we wrote up the SQL to create three tables: CREATE TABLE users( user_id NUMBER, username VARCHAR2(50 CHAR) UNIQUE, CONSTRAINT users_pk PRIMARY KEY (user_id) ); CREATE TABLE projects( project_id NUMBER, Project_name VARCHAR2(50 CHAR) UNIQUE, creator VARCHAR2(50 CHAR) NOT NULL, CONSTRAINT projects_pk PRIMARY KEY (project_id), CONSTRAINT projects_users_fk FOREIGN KEY (creator) REFERENCES users (username) ON DELETE CASCADE ); CREATE TABLE project_users( project_id NUMBER NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, user_id NUMBER NOT NULL REFERENCES users (user_id) ON DELETE CASCADE, CONSTRAINT project_users_pk PRIMARY KEY (project_id, user_id) ); I'm going to increase the size of the users table a bit by adding a first and last name column. CREATE TABLE users( user_id NUMBER, username VARCHAR2(50 CHAR) UNIQUE, first_name VARCHAR2(50 CHAR), last_name VARCHAR2 (50 CHAR), CONSTRAINT users_pk PRIMARY KEY (user_id) ); But before we finish this design, we should consider indexing certain columns. What columns should we index? Well, as a reminder, the columns that are indexed by default are columns with the UNIQUE constraint, and those that are labeled as primary keys. Columns that are not indexed but often should be are those labeled as a foreign key. The column that jumps out the most to me is the creator column of the project table. It's the only foreign key that is not part of some index. Let's fix this by creating our first index. The way we do that is with the CREATE INDEX command. CREATE INDEX projects_creator_ix ON projects (creator) What naming convention are we following for the index? We are naming it by the table name, followed by an underscore, followed by the column, followed by an underscore, followed by an ix (for index). In this situation it does not apply, but if our foreign key column is labeled as UNIQUE, we can add the UNIQUE keyword like this: CREATE UNIQUE INDEX projects_creator_ix ON projects (creator) Now if you want to get rid of an INDEX, you can use this command: DROP INDEX projects_creator_ix Now, if we want to select data from the user table and the project table we can do that much faster. That's because the foreign key and column it references are both indexed and those are the columns we would do the join on. We will discuss how to do joins in a future video. So what are some potential problems with this database design? Overall, it is pretty good. With this design though we need to make sure there is no way for someone to update a user's username. In the next video we are going to discuss why. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me on Patreon! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 7593 Caleb Curry
Oracle SQL Tutorial 8 - Indexes - Database Design Primer 5
 
11:06
The concept of an index is extremely important when managing a database. An index has the power of making your database very quick or it has the power to bog down your update, delete, and insert statements. The trick is to find a good balance. You will want to index any columns that are used continually in a select or a join. By default, all primary keys are indexed as well as any columns with the UNIQUE column attribute. I suggest you consider adding an index to your foreign keys as these will often be used in joins as well. You can actually create an index on a group of columns. This will allow you to search for data and return multiple columns. This is known as a composite index. There are many other things to database design...much more than we have covered. I have decided I will cover these as we go so that we can start applying what we learn practically. Support me: http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 15402 Caleb Curry
Oracle - SQL - Creating Index
 
05:31
Oracle - SQL - Creating Index Watch more Videos at https://www.tutorialspoint.com/videotutorials/index.htm Lecture By: Mr. Anadi Sharma, Tutorials Point India Private Limited.
Oracle - Foreign Keys
 
11:34
Oracle - Foreign Keys
Views: 3802 Chris Ostrowski
Oracle SQL Tutorial 6 - Relationships and Primary and Foreign Keys - Database Design Primer 3
 
29:40
HAPPY VALENTINES DAY!!! Let's talk relationships.. This is the 6th video in your Oracle Database series. We are discussing database relationships which are a key feature of relational database management systems. We first discussed entities and attributes. I talked about how each entity is assigned a table and each attribute is a column within a table. We moved on to the three kinds of relationships. The first was one-to-one. This describes an entity and an attribute. A piece of data that is exclusive to an entity is, by definition, an attribute of that entity. This is stored in one table with the attribute being a column within this table. The second relationship is one-to-many. This relationship is between two entities. The way we properly store this in a database is using a foreign key in the child table. Remember, the child table is the entity on the many side of the one-to-many relationship. Every row within the child table will have a value for the foreign key that references a primary key in the parent table. This assumes that the foreign key field is not optional (NOT NULL). If the foreign key is optional, than a reference is not required but any reference must be valid. The third kind of relationship is a many-to-many relationship. In this situation, we need 3 tables. The many-to-many relationship is broken up into two one-to-many relationships. The intermediary table will associate each entity from one table with the appropriate entities in the other table. There is debate as to whether this table needs a primary key. This is because you can intact use the combination of two foreign keys as a primary key. This works because we will never have two duplicate rows within the intermediary table and the two foreign keys work as a compound key because of this. We finally discussed primary keys and foreign keys. Primary keys are used to keep each row inside of a table unique. If this key is a computer generated number it is known as a surrogate key, otherwise it is known as a natural key. Natural keys have real world meaning. For example, a social security number may work, or an email address (in some situations), etc. Whichever type of key you choose is solely up to you and/or the company you may be working for. HELP ME! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://Twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 40826 Caleb Curry
Oracle SQL Tutorial 20 - How to Create Composite Primary Keys
 
07:02
This video is going to be a tutorial on how to create composite and compound keys. The difference between a composite and compound key is that a composite key can consist of any columns while a compound key has to consist of columns that are all keys themselves. We will be working with a compound key because we are going to be using the an intermediary table that has two foreign keys. The combination of both of the keys have to be unique. First, if we have any other CREATE TABLE commands, we are going to comment those out. We will space out the CREATE TABLE to have each column on a line, then we will add constraints as needed. CREATE TABLE project_users( project_id, user_id ) Now, let's add the data types: CREATE TABLE project_users( project_id NUMBER, user_id NUMBER } Now, what about some column attributes? I'm going to make both of the columns NOT NULL because we always want the rows to have a user and a project: CREATE TABLE project_users( project_id NUMBER NOT NULL, user_id NUMBER NOT NULL } Now, let's add the foreign key constraints. Now, what do we name these? We are going to add a primary key that covers both of these columns, so I'm going to be a sinner and not give these constraints names: CREATE TABLE project_users( project_id NUMBER NOT NULL REFERENCES projects (project_id), user_id NUMBER NOT NULL REFFERENCES users (user_id) ) Now, the way we have it now is that if we delete a project in the project table, and there are any rows in the project_users table, it will throw an error and prevent deletion. I would prefer for it to also delete any project members. That would make sense because if you delete a project we want it to delete the associate between that project and certain users. The same goes for if we delete a user, we want their association with a certain project to be deleted. To do this, we need to add the ON DELETE command: CREATE TABLE project_users( project_id NUMBER NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, user_id NUMBER NOT NULL REFERENCES users (user_id) ON DELETE CASCADE, ) Finally, let's learn how to create a compound or composite key. literally, the only difference is that you put a comma and add the second table inside of the parenthesis. CREATE TABLE project_users( project_id NUMBER NOT NULL REFERENCES projects (project_id) ON DELETE CASCADE, user_id NUMBER NOT NULL REFERENCES users (user_id) ON DELETE CASCADE, CONSTRAINT project_users_pk PRIMARY KEY (project_id, user_id) ) Now, the combination of project_id and user_id cannot be null, is always unique, and has an index. The only thing we should do now is add a few indexes. We aren't done yet...In the next video we are going to figure out what columns would benefit from indexes and we'll add them to it. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HELP ME! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 9453 Caleb Curry
SQL Server 33 - Indexes
 
07:42
Indexes allow us to tell the database that certain columns are columns we want to retrieve commonly. This allows the database to optimize retrieval. Additionally, when we get into the SELECT statement, we will often have to join data from multiple tables. When we correctly add indexes to our tables, we can improve the speed of our SELECT and also our joins. There are two types of Index. One is called clustered and the other is called non-clustered. Clustered indexes determine the actual order of the table. By default this is going to be the primary key column. So when you label a column as PRIMARY KEY, you are also going to be creating an INDEX that is a clustered index. A clustered index is kind of like a telephone book, where the data is right there when you look up a phone number. This means that if you are just making a small database that is only going to store a few things, you may be fine. But more likely than not you are going to want to add additional indexes. When you add a new index, you create a non-clustered index. These things do not actually determine the order of the rows in the table. A way of how you can think of how these work is like an index in the back of a book. The index of the book does not actually contain the data, it just tells you where to find it. What columns do you index? You are going to want every primary key to be indexed. What about foreign keys, are they indexed by default? No, they are not. Of all columns, you are probably going to want to index the foreign keys the most because they are used in joins. Lastly, you will likely want to index columns that you are going to use on a regular basis. You can also make composite indexes just like you can make composite keys. You would want to do this when you are going to constantly being using those columns together. There is a lot to learn on multicolumn indexes. We may explore this concept in more detail and see how SQL Server uses them in a future video, but as of right now it's probably more important that we get a general understanding of all things SQL Server before we deep dive on something like that. In the upcoming videos I'll be teaching you how to create indexes. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 7191 Caleb Curry
Oracle SQL Tuning with Foreign Key Constraints
 
03:02
Learn how to tune SQL with Constraints! In this lesson (2 of 5), OCM John Watson demonstrates how to improve query performance by adding foreign key constraints. See all lessons, free at http://www.skillbuilders.com/oracle-database-sql-tuning-with-constraints.
Views: 430 SkillBuilders
Oracle SQL Tutorial 17 - Designing Our Foreign Keys
 
07:47
We are going to continue working with the users table that we've started with, but we are going to add a few tables. Imagine a system where you can create projects. And users can be added to these projects. So this could be some kind of productivity app or a project management solution, think of JIRA. We are going to start with three tables. The first table is going to be a users table that contains all of the information about each user's account. We are then going to have a table that is called projects. Each project will have data about the project and a foreign key that is the creator of the project. This is a situation where the database design depends a lot on the business rules and requirements of the application. Is it appropriate to have only one creator, or can it have multiple creators? We are going to design it with only one creator per project to increase simplicity. The third table is going to be used to record what users are part of certain projects. This situation is a many to many relationship because we've decided that one user can be a part of multiple projects and an individual project can have multiple members working on it. Because this is a many to many relationship, it calls for an intermediary table, project_users. First, we will draw out the user table. We will have a user_id, username, first_name, and last_name. Now, this is our parent table, because it has no foreign keys. Now, this is our parent table, because it has no foreign keys. Other tables are going to be referencing this table, so they would be the children. The project table will have a project_id, title, description, and creator. The column that needs to be a foreign key is the creator. Let's move on to the next table and we'll get back to the foreign key of the project table. The other table was project_users. Knowing that this is an intermediary table, immediately we know that the first two columns are going to be foreign keys to the each of the other tables. Now, let's ask the important questions about the foreign keys. Let's first start with the project table's user column. The first thing we need to ask is what column does it need to reference? Remember, the only options are the columns that are UNIQUE. Our candidates are user_id and username. For now, let's go with username as it makes things easier to work with. Once we go into learning about joins, we will talk about joining things by ID. Different people do it different ways, with the majority using only ID columns for primary and foreign keys, but it's important to be familiar with different ways of doing things. The important thing to remember is that keys should never change, so if we should only reference the username if a user's username will never change. Should the foreign key be labeled UNIQUE? If yes, it means that a user can only create one project. I vote no. Should the foreign key be labeled NOT NULL? If not, it means that a project can exist without a creator. I vote no. Moving on to the next table, I think I'll have the columns reference the project's id and user's id, so we can get some experience referencing surrogate keys. We can apply to these foreign keys the same questions we asked about the other foreign key, and I would encourage you to do so and really think about why. But I can tell you that we are not going to want them to be NOT NULL, but not UNIQUE. Now that we have a pretty decent database design, we can proceed with creating our database. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HELP ME! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 8822 Caleb Curry
Database Design 21 - Primary Key Index
 
06:28
Donate!: http://bit.ly/DonateCTVM2. Primary key will automatically create an index used for database optimization! More content: http://CalebCurry.com Courses for Download: http://www.udemy.com/u/calebcurry/ Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://Twitter.com/calebCurry Subscribe (it's free!): http://bit.ly/PqPyvH Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 16436 Caleb Curry
Oracle 12C Tutorial 20 - Constraints (Primary, Foreign, Unique, Null etc.)
 
19:41
This Video Tutorial Will Describe about various constraints we can use with tables. Some of the constraints can used as table level or column level so also known as table level constraints and column level constraints. These command will also work on other versions of database like Oracle 11g Database, Oracle 10g Database, Oracle 9i Database, Oracle 8i Database, Oracle 8 Database and so on. In this video i explain Not Null Constraint, Unique key Constraint, Primary Key Constraint, Foreign Key - Reference key Constraint, Check constraint and user_constraints table. Full Syntax will be given in this video tutorial about how to use these constraints. Along with live example to execute Not Null Constraint, Unique key Constraint, Primary Key Constraint, Foreign Key - Reference key Constraint, Check constraint and user_constraints table . All the keywords, format, mandatory clauses etc are described in this video.
Index in oracle
 
16:43
Views: 199 Adam Tech
Oracle SQL Tutorial 7 - Normalization - Database Design Primer 4
 
20:38
The database normal forms are used to normalize a database. What does it mean to normalize a database? It means to break it up into multiple tables to prevent redundant, conflicting, and bad data. The three normal forms are 1nf, 2nf, and 3nf. These stand for first normal form, second normal form, and third normal form. There are other normal forms, such as Boyce Codd normal form (BCNF), but the first 3 normal forms are the ones that are really important to know. The normal forms depend on one another. It is kind of like a ladder. In order to be in 2nd normal form, you must first be in first normal form. In order to be in 3rd normal form, you must first be in 2nd normal form. First normal form is all about individuality and giving data its space. Each column must be atomic...that is, in the smallest indivisible piece. Each value for the column must also only contain one value. To fix first normal form when you have a column violation, break the column into multiple columns. To fix first normal form when you have data violation, break the column into a new table and have a column that references the old table. Second normal form is all about partial dependencies. A partial dependency is when a column only depends on part of the primary key. This is often seen when you have an intermediary table in a many to many relationship (as a reminder, we break up many to many relationships into one to many relationships with intermediary tables in between). The solution to get rid of partial dependencies is to put the data in the table to where the column depends entirely on the key. If you do not already have a table that fits the rule, you can consider creating one. Third normal form is all about transitive dependencies. This is when a column in a table depends on another column instead of depending solely on the primary key. The solution to this is to take the column that is directly dependent on the primary key and bring it into its own table. Then, you can use foreign keys to connect the tables. This video concluded with a noble speech on how database design is very subjective. Thus is so because as we normalize more and more, the design becomes more and more complex. If we get to the point where we have hundreds of tables for a relatively small database, we can really hurt performance and increase risk of mistakes. Hopefully this video was helpful to everyone. See you in the next one! Support me: http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 23448 Caleb Curry
Oracle SQL Tutorial 4 - Beginner Terms - Database Design Primer 1
 
14:11
The terms covered in this video are: SQL RDBMS Relations NULL Database design Relationships Primary key Foreign key Constraint Indexes Data type HELP ME! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://Twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 57398 Caleb Curry
SQL in Oracle 11g Tutorial #9: Implementation/Example of Primary Key and Foreign Key
 
08:52
SQL in Oracle 11g Tutorial #9: Implementation/Example of Primary Key and Foreign Key. How to create a Primary Key. How to create a Foreign Key. Thanks for Watching my Channel “Learn TechToTech”. Please subscribe my channel for getting first updates after uploading video.Social Media pages of Channel are: 1. My Website : www.learnfromrakesh.com 2. My Twitter: https://twitter.com/LearnTechtotech 3. Facebook Page: https://www.facebook.com/LearnTechToTech 4. Blogger : https://learntechtotech.blogspot.in/ 5. Google+ : https://learntechtotech.blogspot.in/ 6. Pinterest : https://in.pinterest.com/LearnTechToTech/ 7. LinkedIn: https://www.linkedin.com/in/Learntechtotech/ Playlist of Different Technology: 1. Operating System : https://goo.gl/q6SfrW 2. Python Programming Language : https://goo.gl/L8b5dc 3. C Language : https://goo.gl/SwvDu9 4. C language for Placement: https://goo.gl/AaQBa4 5. Java: https://goo.gl/M8F2uy 6. MySql : https://goo.gl/vdJbHQ 7. Android Mobile Application Development: https://goo.gl/M6woaT 8. Kotlin Programming Language : https://goo.gl/GXE5cd 9. Go Programming: https://goo.gl/Ua3xYW 10. Internet of Things(IoT): https://goo.gl/f2afkY 11. Oracle 11g : https://goo.gl/zds8r2 12. C++ : https://goo.gl/C1psMT
Views: 87 Learn TechToTech
Oracle SQL Tutorial 12 - Intro to Constraints
 
06:13
As I believe I've mentioned in an earlier video, a constraint is basically a rule we can put in our database that prevents someone from putting the wrong data in. It protects our relationships and data integrity. Because the goal of these constraints are to protect our data integrity, you may hear them called integrity constraints. There are many integrity constraints we are going to talk about: NOT NULL UNIQUE PRIMARY KEY FOREIGN KRY CHECK There is also the DEFAULT attribute. These are all keywords we can add to our columns that will change the way the database works with our data and also prevents incorrect data. NOT NULL is a constraint you can put on a column that prevents nulls. A null is the absence of a value. When we say null, we are saying that every single row has to have a value for this column. UNIQUE is a constraint that makes every row have a unique value for this column. Now note, this does not require values to be put it, and it will allow multiple rows to be null. Next, we are going to talk about primary keys. What qualifies a column as a candidate key? First, not a single row should have a null for that column. Second, every row must be unique. The primary key constraint is essentially a combination of the NOT NULL constraint and the UNIQUE constraint. The foreign key constraint sets the requirement that any value in this column for any row must match a row in another column. Check constraints allow us to be more strict with what data is allowed in our database. NOT NULL and UNIQUE give some level of restriction, but what if we want something more specific? For example, what if we only want values between 0 and 100? That is where check constraints come in. When using check constraints, you give a boolean expression. A boolean expression is something that can be evaluated to true or false. It will only insert the row if the value you try to put into the row makes the expression evaluate to true. So if you put in a value too great or small, the expression will be false and the data is not allowed to be entered. The default constraint is a value you can give a column, and if for any reason when the row is created in the table a value is not provided, the default value will be given. So for example, we could have a bank account table where the balance defaults to 0. How do you actually implement these constraints when you are creating a table? In the next video we are going to be adding these to our users table. Please be sure to subscribe! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me on Patreon: http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 17899 Caleb Curry
Database Tutorial - 18 - Creating Index
 
03:59
Please Rate, Comment and Subscribe. Available for Hire: http://www.naveedziarab.com Twitter: https://twitter.com/CreativityTuts Website: http://www.creativitytuts.org
Views: 9960 Naveed Ziarab
SQL Server 34 - How to Create and Drop Indexes
 
05:15
Creating indexes is a very easy task, but before you go creating indexes on everything, you need to know that some columns are indexed by default. Specifically, any column that is labeled as the PRIMARY KEY or UNIQUE are indexed by default. That means that if you have a UNIQUE column, you do not need to worry about adding an INDEX to it. The columns that you will want to pay special attention to are any foreign keys or columns that you are going to use very frequently. We are going to create an index on our SpeciesID column in our Animals table. This is a foreign key that I'm likely going to use very frequently. CREATE INDEX IX_AnimalsSpecies ON Animals (SpeciesID); The syntax is very similar to CREATE TABLE in that you say CREATE INDEX followed by an index name. The IX_ is a prefix that is sometimes conventionally used to name indexes. Next, we have the table name, and then we have something to describe the column. That way if you see IX_AnimalsSpecies, you automatically know it is talking about an Index for the Animals table that is on the column dealing with the species. To get rid of this index, use this: DROP INDEX IX_AnimalsSpecies; Which is also very similar to how we drop a table. Now, you can also create an INDEX on multiple columns if you are going to use them together very often. The way you do that is just add another column after a comma inside of the () in the index columns. For example: CREATE INDEX IX_AnmialsContact ON Animals (Name, ContactEmail); One other thing I wanted to show you is that you can actually create a UNIQUE Index by adding the keyword in: CREATE UNIQUE INDEX IX_Species ON Species (Species); This should only be used if every value for a column is labeled unique…In fact, it forces every row to be unique. Remember though that if a column is labeled UNIQUE, it is indexed by default...So this is not needed in this situation. In the next video we will discuss in more detail whether you want to use the UNIQUE Constraint create a UNIQUE index. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 7122 Caleb Curry
Oracle - SQL - Primary Key Constraint
 
04:10
Oracle - SQL - Primary Key Constraint Watch more Videos at https://www.tutorialspoint.com/videotutorials/index.htm Lecture By: Mr. Anadi Sharma, Tutorials Point India Private Limited.
CREATE TABLE WITH CONSTRAINTS - ORACLE - SQL
 
20:35
Create table , add constraints : primary key constraint, foreign key constraint, check constraint, unique constraint, specifying the table space for index, modifying table, dropping table Oracle 10g
Views: 9812 R.N.A. Creation
Database Tables, Primary Keys, Foreign Keys, and Relationships
 
14:37
Explaining the basic constructs of a relational database: Tables, Primary Keys, Foreign Keys, and Relationships. The database is normalized.
Views: 349283 minderchen
Working with Primary & Foreign key Constraint in SQL Server | SQL Server Tutorial
 
24:13
** For Online Training Registration: https://goo.gl/r6kJbB ? Call: +91-8179191999 ? Visit Our Website for Classroom Training: https://nareshit.in/sql-server-training/ ? For Online Training: https://nareshit.com/course/sql-server-online-training/ #sqlserver #server #programming #course #Tutorials #Training #Videos -------------------------- ? About NareshIT: "Naresh IT is having 14+ years of experience in software training industry and the best Software Training Institute for online training, classroom training, weekend training, corporate training of Hadoop, Salesforce, AWS, DevOps, Spark, Data Science, Python, Tableau, RPA ,Java, C#.NET, ASP.NET, Oracle, Testing Tools, Silver light, Linq, SQL Server, Selenium, Android, iPhone, C Language, C++, PHP and Digital Marketing in USA,Hyderabad, Chennai and Vijayawada,Bangalore India which provides online training across all the locations -------------------------- ? Our Online Training Features: 1.Training with Real-Time Experts 2.Industry Specific Scenario’s 3.Flexible Timings 4.Soft Copy of Material 5. Share Videos of each and every session. -------------------------- Please write back to us at [email protected]/[email protected] or Call us at USA: +1404-232-9879 or India: +918179191999 ** Check The Below Links** ? For Course Reg: https://goo.gl/r6kJbB ? Subscribe to Our Channel: https://goo.gl/q9ozyG ? Circle us on G+: https://plus.google.com/NareshIT ? Like us on Facebook: https://www.facebook.com/NareshIT ? Follow us on Twitter: https://twitter.com/nareshitech ? Follow us on Linkedin: https://in.linkedin.com/company/naresh-i-technologies ? Follow us on Instagram: https://www.instagram.com/nareshitech/
Views: 51495 Naresh i Technologies
Differences between primary key and unique key - SQL Server Interview Questions
 
06:07
Hi Friends, In this in this session we are going to learn the differences between primary key and unique key This is one of the most frequently asked sql server interview questions. Before we discuss the difference between primary key and unique key, let's see what a primary key is and what a unique key is. Primary Key: Primary key is a key which uniquely identifies each row/record in the table. This implies if you have a primary key on a table, you can identify each and every row in that table uniquely using primary key. Unique Key: Unique key constraint enforces the uniqueness on the columns in which it is defined. That is Unique key will make sure only unique values are allowed in the columns in which it is defined. Similarities: Both Primary key and unique Key enforces uniqueness on the columns on which they are defined. • Primary key and unique Key columns allow only unique values. • Primary key and unique Key columns will avoid duplicates • Both Primary key and unique Key columns uniquely identifies each row/record in the table Differences: PRIMARY KEY UNIQUE KEY Primary Key Does not allow duplicates Unique key allows only one NULL A table can have only 1 Primary Key A table can have multiple Unique Keys By default Primary Key creates a Unique Clustered Index on the table By default Unique Key creates a Unique Non-Clustered Index on the table. I hope this session is clear and i hope this knowldge should help you in interviews. Please share your valuable comments & sugesstions. Also, subscriber to my channel for more sql server interview questions and answers. Bye bye & Have a good day.
Views: 37121 TheSSScreations
What is the Difference between Primary Key and Unique Key - Database Tutorial 14
 
04:51
Database Tutorial. This video is about Database Fundamentals. I hope this series of videos can help those who want to be Database Professionals. I will cover various database technologies including Oracle Database, Microsoft SQL Server database and Sybase. Video: What is the Difference between Primary Key and Unique Key (Video 14 in the Database Tutorial Series) (Common for Oracle/Microsft SQL Server/Sybase /MySQL)
Views: 33212 Sam Dhanasekaran
Oracle Tutorial - 10 - indexes
 
10:36
Oracle PL/SQL Query Database. Check more videos on IT courses on iAspireAcademy.org
Views: 22464 iAspireAcademy
Creating Primary and Foreign Keys in SQL Server 2012
 
18:22
Dr. Soper shows how to create simple and composite primary keys and foreign key relationships in a SQL Server database using SQL Server Management Studio. Several different methods of creating keys and establishing relationships between tables are demonstrated.
Views: 395871 Dr. Daniel Soper
mysql tutorial for beginners (6/8) : Indexes
 
05:48
mysql tutorial for beginners (6/8) : Indexes As things stand, the table students works and can be searched without problem by MySQL—until it grows to more than a couple of hundred rows, At that point, database accesses will get slower and slower with every new row added, because MySQL has to search through every row whenever a query is issued. This is like searching through every book in a library whenever you need to look something up. Of course, you don’t have to search libraries that way, because they have either a card index system or, most likely, a database of their own. The way to achieve fast searches is to add an index, either when creating a table or at any time afterward. But the decision is not so simple. For example, there are different index types such as a regular INDEX, PRIMARY KEY, and FULLTEXT. Also, you must decide which columns require an index, a judgment that requires you to predict whether you will be searching any of the data in that column. And even when you’ve decided that, you still have the option of reducing index size by limiting the amount of each column to be indexed. If we imagine the searches that may be made on the students table, it becomes apparent that all of the columns may need to be searched. Anyway, go ahead and add an index to each of the columns, using the commands: ALTER TABLE students ADD INDEX(name(3)); An alternative to using ALTER TABLE to add an index is to use the CREATE INDEX command. They are equivalent, except that CREATE INDEX cannot be used for creating a PRIMARY KEY CREATE INDEX surname ON students (surname(5)); DESCRIBE students; These commands create indexes on both the name and surname columns, limiting name index to only the first 3 characters, and surname index to the first 5 characters. For instance, when MySQL indexes the following name: SAFAA It will actually store in the index only the first 3 characters: SAF This is done to minimize the size of the index, and to optimize database access speed. DESCRIBE command shows the key MUL for each column. This key means that multiple occurrences of a value may occur within that column, which is exactly what we want, as name or surname may appear many times. You don’t have to wait, until after creating a table to add indexes. In fact, doing so can be time-consuming, as adding an index to a large table can take a very long time. Therefore, let’s look at a command that creates the table students with indexes already in place. CREATE TABLE students ( Id_studnet SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, name VARCHAR(10) NOT NULL, surname VARCHAR(20) NOT NULL, email VARCHAR(30) NOT NULL, INDEX(name(3)), INDEX(surname(5)), ,PRIMARY KEY(id_studnet),UNIQUE(email)); Another important index, PK, its single unique key for each student to enable instant accessing of a row. The importance of having a key with a unique value for each row will come up when we start to combine data from different tables. You can add PK, while you create the table at the first time, or later by issuing the following command: ALTER TABLE students ADD PRIMARY KEY(id_student); The last important index, FULLTEXT index Unlike a regular index, MySQL’s FULLTEXT allows super-fast searches of entire columns of text. It stores every word in every data string in a special index that you can search using “natural language,” in a similar manner to using a search engine. It’s not strictly true that MySQL stores all the words in a FULLTEXT index, because it has a built-in list of more than 500 words that it chooses to ignore because they are so common that they aren’t very helpful for searching anyway. This list, called stopwords, includes the, as, is, of, and so on. The list helps MySQL run much more quickly when performing a FULLTEXT search and keeps database sizes down. FULLTEXT indexes can be created for CHAR, VARCHAR, and TEXT columns only. A FULLTEXT index definition can be given in the CREATE TABLE statement when a table is created, or added later using ALTER TABLE (or CREATE INDEX). Adding a FULLTEXT index to the table students for the columns name and surname ALTER TABLE classics ADD FULLTEXT(name,surname); this index is in addition to the ones already created and does not affect them You can now perform FULLTEXT searches across this pair of columns. If you find that MySQL is running slower than you think it should be when accessing your database, the problem is usually related to your indexes. Either you don’t have an index where you need one, or the indexes are not optimally designed. Tweaking a table’s indexes will often solve such a problem. In the next tutorial, we will learn about, using FOREIGN KEY Constraints and how to join tables together. Subscribe for more: ---------------------------------------------------------------------------- https://www.youtube.com/subscription_center?add_user=saf3al2a SWE.Safaa Al-Hayali - saf3al2a
Views: 25194 Safaa Al-Hayali
Oracle Tutorial || Oracle| Sql Constraints Part - 1 by basha
 
33:21
DURGASOFT is INDIA's No.1 Software Training Center offers online training on various technologies like JAVA, .NET , ANDROID,HADOOP,TESTING TOOLS ,ADF,INFORMATICA,TABLEAU,IPHONE,OBIEE,ANJULAR JS, SAP... courses from Hyderabad & Bangalore -India with Real Time Experts. Mail us your requirements to [email protected] so that our Supporting Team will arrange Demo Sessions. Ph:Call +91-8885252627,+91-7207212428,+91-7207212427,+91-8096969696. http://durgasoft.com http://durgasoftonlinetraining.com https://www.facebook.com/durgasoftware http://durgajobs.com https://www.facebook.com/durgajobsinfo......
Oracle SQL Tutorial 19 - ON DELETE (SET NULL and CASCADE)
 
05:59
Welcome everyone! Something you need to consider when you are creating foreign keys is what happens if you delete the parent? As a reminder, the parent is the row that has the value you are referencing in the row that has a foreign key. Why is this something important to consider? It's important because foreign keys need to protect us from two primary things, unacceptable INSERT statements, and unacceptable DELETE statements. Let's see what happens when we try to insert incorrect data into the table with the foreign key: INSERT INTO projects VALUES (1, 'Update website homepage', 'CalebCurry') The response tells us plainly that there is no such user in the users table. So this works correctly. Deleting data on the other hand works a bit differently because the database does not know what you want to do with the child row when you delete the parent from the parent table. By default, we will get an error message that prevents the parent from being deleted, but there are some other options. How do we configure this? This is where the ON DELETE statement comes in. We add the keywords ON DELETE right after the foreign key and then we can give it the option of CASCADE or SET NULL. CASCADE means that if we delete the parent, we are also going to delete the child. In our situation what that means is that if somebody creates a project in our project table and then that persons account gets deleted, all of the projects he owns will also be deleted. CASCADE: CREATE TABLE projects( project_id NUMBER, Project_name VARCHAR2(50 CHAR) UNIQUE, creator VARCHAR2(50 CHAR) NOT NULL, CONSTRAINT projects_pk PRIMARY KEY (project_id), CONSTRAINT projects_users_fk FOREIGN KEY (creator) REFERENCES users (username) ON DELETE CASCADE ) SET NULL will take the value in the child table and get rid of it. What you are left with is NULL. This means that we have an orphaned child. The first thought you might have is that it is a bad thing to have an orphaned child, but in databases that is not always so. In our application if we had it set to SET NULL, when a user account gets deleted the projects would remain in existence they would just lack a creator. This might be a good thing if you are concerned about the long term survival of a project, this might be the route you want to go. It ultimately depends on the application purpose. If you don't like CASCADE or SET NULL, you can leave the entire ON DELETE statement and just have Oracle throw an error when a parent is deleted. As for us, we are going to use ON DELETE CASCADE. We need to use this with extreme caution. If you are not careful, someday you will run a delete a row and that will cascade through you database deleting a bunch of stuff you didn't want to delete. Stuff happens, so make sure you back up your database every once in eternity. Now, in the last video we started with a database design that had three tables. We've only created two in this video. In the next video we are going to create the next one, which is a little special. Then we'll finish things up by adding some indexes. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me on Patreon! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 13223 Caleb Curry
Indexing within Relational Databases SQL Server / Oracle / Others
 
09:21
SQL Server and Relational Database Indexing - If you enjoyed the video, please +1 it or subscribe for more to follow! Get SQL Server with BI - Free Express (Limits to 4 Gigs of Ram on Processing) http://www.microsoft.com/download/en/details.aspx?id=25174
Oracle - Primary Keys
 
08:37
Oracle - Primary Keys
Views: 2694 Chris Ostrowski
Oracle ||  Referential Integrity Constrants Part-1 by Dinesh
 
25:04
DURGASOFT is INDIA's No.1 Software Training Center offers online training on various technologies like JAVA, .NET , ANDROID,HADOOP,TESTING TOOLS ,ADF,INFORMATICA,TABLEAU,IPHONE,OBIEE,ANJULAR JS, SAP... courses from Hyderabad & Bangalore -India with Real Time Experts. Mail us your requirements to [email protected] so that our Supporting Team will arrange Demo Sessions. Ph:Call +91-8885252627,+91-7207212428,+91-7207212427,+91-8096969696. http://durgasoft.com http://durgasoftonlinetraining.com https://www.facebook.com/durgasoftware http://durgajobs.com https://www.facebook.com/durgajobsinfo......
SQL Server 15 - Composite Key
 
07:57
An interesting thing you can do with primary keys is that you can make a combination of columns the primary key. This is important when more than one column is required to make something unique. In an intermediary table, instead of having an association ID, we can have the combination of two rows as the primary key. This is known as either a compound or composite primary key. In the situation of using natural keys, composite keys are more common. For example, you could have a shopping website that allows multiple people from the same household to use a certain coupon you sent out. In this situation, you could use the address and the person's name as the natural primary key. What is the difference between a primary key and a column that has UNIQUE and NOT NULL constraints? The primary difference has to do with indexing. When you create a primary key, the column will automatically be indexed. This means that working with this data is faster. Now, we haven't talked a ton on indexes, but by default this will create a clustered index. UNIQUE constraints are also indexed by default, but the default index for a UNIQUE constraint is a non-clustered index. Clustered indexes determine how the table is actually stored, while non clustered indexes will make a sorted list that has reference to the data. This is not a life changing difference because these can actually be changed. We will discuss all of the details of indexing in future videos. As a side note, the IDENTITY column is not automatically indexed. How do we reference primary keys? This requires what is known as a foreign key, which we will discuss in the next video. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 8855 Caleb Curry
Oracle||Oracle Integrity Constrants Patr -1 by Dinesh
 
32:48
DURGASOFT is INDIA's No.1 Software Training Center offers online training on various technologies like JAVA, .NET , ANDROID,HADOOP,TESTING TOOLS ,ADF,INFORMATICA,TABLEAU,IPHONE,OBIEE,ANJULAR JS, SAP... courses from Hyderabad & Bangalore -India with Real Time Experts. Mail us your requirements to [email protected] so that our Supporting Team will arrange Demo Sessions. Ph:Call +91-8885252627,+91-7207212428,+91-7207212427,+91-8096969696. http://durgasoft.com http://durgasoftonlinetraining.com https://www.facebook.com/durgasoftware http://durgajobs.com https://www.facebook.com/durgajobsinfo......
Oracle Constraints
 
27:50
Oracle SQL Tutorials For Full Course Experience Please Go To http://mentorsnet.org/course_preview?course_id=4 Full Course Experience Includes 1. Access to course videos and exercises 2. View & manage your progress/pace 3. In-class projects and code reviews 4. Personal guidance from your Mentors
Views: 20129 Oresoft LWC
Oracle Unique Constraint تعليم اوراكل
 
08:22
by Mohamed El Desouki - محمد الدسوقى [email protected] Tel :00966 553450836 جامعة سلمان بن عبد العزيز - السعودية - الخرج How To Add Unique Constraint to Table. Unique كيف تستخدم قيد الــ Text Book: Fundamentals of Database Systems, 5th Edition, by Elmasri/Navathe, published by Addison-W oracle create table statement oracle drop table statement oracle constraints database constraints primary key constraint foreign key constraint check constraint null not null constraint unique constraint
Oracle SQL Tutorial 22 - Why Primary Keys Shouldn't Change
 
07:14
In the last video I mentioned that with our database design it is important to make sure that nobody tries to update a user's username. What happens if they do? Nothing horrible, Oracle will just throw an error. That's not such a big deal, but if you are hoping to make some kind of application that allows someone to change their username, this is not the best set up. Why? If you look at the projects table, we have a foreign key that references the username. Let's assume for a moment that Oracle allows you to do anything with your data. That means that if a user updates their username, there will be projects created by users that don't exist. Or a user could change their name to the previous owner. To fix this problem, we would need something such as an ON UPDATE CASCADE command for our foreign key. That would mean that if the user updated their username, the columns that reference that username would also update to the new value. This exists in some database management systems, but this does not exist in Oracle at the time of this video. How do we get around this problem? I'm sure we could conjure up something to allow us to update the username, but the easiest solution is to reference the user_id instead of the username. That way, when the username is updated, nothing changes inside of the foreign key. As a general rule, primary keys should never change. Foreign keys CAN change, but they should not change because a primary key changed. So, if we did happen to use a username as a column, it would be frowned upon if the username had to change because the column it references changes. However, it would be acceptable to change the foreign key if we needed to point to a new entity in the users table. Even if a username is never intended to change, these complications bother a lot of people. You can mitigate these problems by only referencing surrogate keys in foreign keys. This has the downside though that when you retrieve the data, you are going to have to do more work to make the data readable. For example, we had a table that was called project_users. It is essentially a table that says what users are part of what projects. We could have the foreign keys reference the project's name and the user's username. Then when you could say SELECT * FROM project_users. The data would be completely readable without doing anything. If you switch to only referencing surrogate primary keys, you will have a bunch of random numbers that don't mean anything and will have to be joined with other tables…which is really super frustrating when later you have to join a thousand tables to read anything. Which side do you prefer? Pick a side. Choose wisely. I'll see you all in the next video ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HELP ME! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 5135 Caleb Curry
Oracle index creation monitoring
 
01:50
Analyzing an Oracle index creation with d.side - Automatic diagnostic for Oracle databases performance and troubleshooting http://www.dside-software.com Copyright (c) d.side software
Views: 204 D.SIDE SOFTWARE
12 UNIQUE and FOREIGN KEY Constraints in SQL Server
 
11:30
with Arabic content by easy way to learn شرح بالعربي
120. Composite Key in SQL (Hindi)
 
09:11
Please Subscribe Channel Like, Share and Comment Visit : www.geekyshows.com
Views: 13238 Geeky Shows
Tutorial 13-  PRIMARY KEY AND FOREIGN KEY
 
13:45
Learn about PRIMARY KEY AND FOREIGN KEY in PostgreSQL.
Views: 20742 Programming Guru
Part 12   Can we join two tables without primary foreign key relation
 
10:38
Link for all dot net and sql server video tutorial playlists http://www.youtube.com/user/kudvenkat/playlists Link for slides, code samples and text version of the video http://csharp-video-tutorials.blogspot.com/2014/09/part-12-can-we-join-two-tables-without.html Can we join two tables without primary foreign key relation Yes, we can join two tables without primary foreign key relation as long as the column values involved in the join can be converted to one type. ID column in Departments table is not the primary Key and DepartmentId column in Employees table is not the foreign key. But we can still join these tables using ID column from Departments table and DepartmentId column from Employees table, as both the columns involved in the join have same data type i.e int. Select Employees.Name as EmployeeName, Departments.Name as DepartmentName from Employees join Departments on Departments.ID = Employees.DepartmentId The obious next question is, if primary foreign key relation is not mandatory for 2 tables to be joined then what is the use of these keys? Primary key enforces uniqueness of values over one or more columns. Since ID is not a primary key in Departments table, 2 or more departments may end up having same ID value, which makes it impossible to distinguish between them based on the ID column value. Foreign key enforces referential integrity. Without foreign key constraint on DepartmentId column in Employees table, it is possible to insert a row into Employees table with a value for DepartmentId column that does not exist in Departments table. The following insert statement, successfully inserts a new Employee into Employees table whose DepartmentId is 100. But we don't have a department with ID = 100 in Departments table. This means this employee row is an orphan row, and the referential integrity is lost as result Insert into Employees values (8, 'Mary', 'Female', 80000, 100) If we have had a foreign key constraint on DepartmentId column in Employees table, the following insert statement would have failed with the following error. Msg 547, Level 16, State 0, Line 1 The INSERT statement conflicted with the FOREIGN KEY constraint. The conflict occurred in database "Sample", table "dbo.Departments", column 'ID'.
Views: 108998 kudvenkat
Oracle - SQL - Managing Constraints
 
06:01
Oracle - SQL - Managing Constraints Watch more Videos at https://www.tutorialspoint.com/videotutorials/index.htm Lecture By: Mr. Anadi Sharma, Tutorials Point India Private Limited.
SQL Server 29 - How to Name Constraints
 
03:42
Our database has some primary and foreign keys, but occasionally people want to name them. That way, we can refer to a constraint specifically by a user friendly name. The trick is to simply add CONSTRAINT xx_ConstraintName before the constraint. Typically, the constraint name will follow the pattern of 2 letters to represent what type of constraint, followed by an Underscore, followed by the name. Here is an example: CREATE TABLE Interests( AnimalID INT NOT NULL, SpeciesID INT NOT NULL, CONSTRAINT PK_Interests PRIMARY KEY (AnimalID, SpeciesID) ); Now what do you name the constraint? Ultimately, that is a decision that is up to you. There are some conventions. The convention I used in this example is known as Hungarian notation. Hungarian notation is when we include what the thing is inside of the name. By prefixing the name with PK_ we automatically know that this is a primary key constraint. Some people prefer to put the PK at the end, and some people don't like to put it in there at all. Then, after the PK_, I put the name of the table to say that it is the primary key for that table. We can do the same with the foreign keys: CREATE TABLE Interests( AnimalID INT NOT NULL, SpeciesID INT NOT NULL, CONSTRAINT FK_InterestsAnimals FOREIGN KEY (AnimalID) REFERENCES Animals(ID), CONSTRAINT FK_InterestsSpecies FOREIGN KEY (AnimalID) REFERENCES Animals(ID), CONSTRAINT PK_Interests PRIMARY KEY (AnimalID, SpeciesID) ); The naming convention for the foreign keys is FK_ followed by the table name, followed by the Table it references. This is an okay naming convention. It can get confusing if you, for example had two columns from the Interests table referencing the Animals table. Much better. Why is it so important to name constraints? One of the primary reasons is so if SQL Server ever complains about a constraint violation, you will know exactly what constraint it is talking about without having to go search for it: INSERT INTO Interests VALUES (1, 3); SQL Server responds with: "The INSERT statement conflicted with the FOREIGN KEY constraint "FK_InterestsAnimals". This is an example of an INSERT statement. We will introduce this in more detail in the next video. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://bit.ly/JoinCCNewsletter Donate!: http://bit.ly/DonateCTVM2. ~~~~~~~~~~~~~~~Additional Links~~~~~~~~~~~~~~~ More content: http://CalebCurry.com Facebook: http://www.facebook.com/CalebTheVideoMaker Google+: https://plus.google.com/+CalebTheVideoMaker2 Twitter: http://twitter.com/calebCurry Amazing Web Hosting - http://bit.ly/ccbluehost (The best web hosting for a cheap price!)
Views: 1833 Caleb Curry
Improve Webi Performance with Index Awareness : SAP BusinessObjects
 
08:34
Index awareness is the ability to take advantage of the indexes on key columns to speed data retrieval. We set up index awareness in Designer for object definitions and tell Designer which database columns are primary and foreign keys. Report query can take advantage of the indexes on key columns to speed query results. It is one of ways to improve webi query performance.
Views: 5544 aroundBI
SQL script to insert into many to many table
 
14:52
Text Article http://csharp-video-tutorials.blogspot.com/2017/02/sql-script-to-insert-into-many-to-many.html Slides http://csharp-video-tutorials.blogspot.com/2017/02/sql-script-to-insert-into-many-to-many_6.html SQL Server Interview Questions and Answers text articles & slides http://csharp-video-tutorials.blogspot.com/2014/05/sql-server-interview-questions-and.html SQL Server Interview Questions and Answers playlist https://www.youtube.com/playlist?list=PL6n9fhu94yhXcztdLO7i6mdyaegC8CJwR All Dot Net and SQL Server Tutorials in English https://www.youtube.com/user/kudvenkat/playlists?view=1&sort=dd All Dot Net and SQL Server Tutorials in Arabic https://www.youtube.com/c/KudvenkatArabic/playlists In this video we will discuss how to insert data into a table that has many-to-many relationship Create table Students ( Id int primary key identity, StudentName nvarchar(50) ) Go Create table Courses ( Id int primary key identity, CourseName nvarchar(50) ) Go Create table StudentCourses ( StudentId int not null foreign key references Students(Id), CourseId int not null foreign key references Courses(Id) ) Go Students - Id column is identity column Courses - Id column is identity column StudentCourses - StudentId and CourseId columns are foreign keys referencing Id column in Students and Courses tables As you can see, StudentCourses is a bridge table that has many to many relationship with Students and Courses tables. This means a given student can be enrolled into many courses and a given course can have many students enrolled. Below is the question asked in an interview for SQL Server Developer role. Write a SQL script to insert data into StudentCourses table. Here are the rules that your script should follow. 1. There will be 2 inputs for the script Student Name - The name of the student who wants to enroll into a course Course Name - The name of the course the student wants to enroll into 2. If the student is already in the Students table, then use that existing Student Id. If the student is not already in the Students table, then a row for that student must be inserted into the Students table, and use that new student id. 3. Along the same lines, if the course is already in the Courses table, then use that existing Course Id. If the course is not already in the Courses table, then a row for that course must be inserted into the Courses table, and use that new course id. 4. There should be no duplicate student course enrollments, i.e a given student must not be enrolled in the same course twice. For example, Tom must not be enrolled in C# course twice. Answer : To avoid duplicate student course enrollments create a composite primary key on StudentId and CourseId columns in StudentCourses table. With this composite primary key in place, if someone tries to enroll the same student in the same course again we get violation of primary key constraint error. Alter table StudentCourses Add Constraint PK_StudentCourses Primary Key Clustered (CourseId, StudentId) Here is the SQL script that inserts data into the 3 tables as expected Declare @StudentName nvarchar(50) = 'Sam' Declare @CourseName nvarchar(50) = 'SQL Server' Declare @StudentId int Declare @CourseId int -- If the student already exists, use the existing student ID Select @StudentId = Id from Students where StudentName = @StudentName -- If the course already exists, use the existing course ID Select @CourseId = Id from Courses where CourseName = @CourseName -- If the student does not exist in the Students table If (@StudentId is null) Begin -- Insert the student Insert into Students values(@StudentName) -- Get the Id of the student Select @StudentId = SCOPE_IDENTITY() End -- If the course does not exist in the Courses table If (@CourseId is null) Begin -- Insert the course Insert into Courses values(@CourseName) -- Get the Id of the course Select @CourseId = SCOPE_IDENTITY() End -- Insert StudentId & CourseId in StudentCourses table Insert into StudentCourses values(@StudentId, @CourseId) If required, we can very easily convert this into a stored procedure as shown below. Create procedure spInsertIntoStudentCourses @StudentName nvarchar(50), @CourseName nvarchar(50) as Begin Declare @StudentId int Declare @CourseId int Select @StudentId = Id from Students where StudentName = @StudentName Select @CourseId = Id from Courses where CourseName = @CourseName If (@StudentId is null) Begin Insert into Students values(@StudentName) Select @StudentId = SCOPE_IDENTITY() End If (@CourseId is null) Begin Insert into Courses values(@CourseName) Select @CourseId = SCOPE_IDENTITY() End Insert into StudentCourses values(@StudentId, @CourseId) End Use the following statement to execute the stored procedure Execute spInsertIntoStudentCourses 'Tom','C#'
Views: 73720 kudvenkat
SQL Index - Compare a clustered index vs a non clustered index
 
09:54
http://sqlserver2008tutorial.com/ In this video training, we compare SQL indexes -- clustered index vs. non clustered index. In SQL server you can have one clustered index whereas you can have many non clustered index is. Using SQL Server Profiler and MS SQL Execution plans, we compare the clustered index and the nonclustered index. In this demo we show you how to create a clustered and non-clustered index using SSMS. Using different parameters like CPU, Number of Page Reads and Duration in msec, we come to a conclusion that the best option is to use a clustered index. Finally we go over index management and index fragmentation. We illustrate ALTER TABLE commands with Index Rebuild or Index Reorg. Other topics that we cover include a table scan; clustered index scan and an index seek.
Views: 50551 baghul

7 eleven employment application online
Writing letter to judge uk
Application letters in nigeria what is bta
Resume cover letter example australian
Law cover letter samples