Home
Search results “Set null in update oracle”
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://eepurl.com/-8qtH 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 - https://www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)
Views: 10789 Caleb Curry
118. ON UPDATE SET NULL in SQL (Hindi)
 
02:23
Please Subscribe Channel Like, Share and Comment Visit : www.geekyshows.com
Views: 2184 Geeky Shows
MySQL 17 - ON DELETE and ON UPDATE
 
04:32
Now, what happens when you have successfully created a reference, and now you try deleting the parent? This is where the ON DELETE clause come in. This is essentially how we configure how strict a foreign key is. There are 3 options you can give for an ON DELETE: RESTRICT / NO ACTION Yes - In MySQL they are the same, but not all DBMS. CASCADE Yes SET NULL Yes Now the default is RESTRICT. This means that when you try to delete a parent row, MySQL is going to throw an error and not let you. Cascade means that if you delete the parent row, any rows that reference that parent will also be deleted. This is pretty dangerous and not often recommended. SET NULL will set the foreign key to be NULL. Now obviously, this is going to require that the foreign key is not labelled NOT NULL. In addition to the ON DELETE clause, there is the ON UPDATE clause. This one is a little less common because it configures what happens when a parent value changes. Obviously, when you are referencing a primary key, the ON UPDATE clause is nearly useless. That's because the primary key value is never supposed to change. If, on the other hand, we have a foreign key referencing a UNIQUE column that is not a primary key, it may change occasionally. So the only times you have to worry about the ON UPDATE clause is with foreign keys referencing UNIQUE columns that are not a primary key, and when you have natural keys that break the rules and actually do change at some point in time. The ON UPDATE clause has the same options as the ON DELETE clause and they all work the same way. Now, the last thing you need to know about foreign keys is that they must match the data type of the column you are referencing. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://eepurl.com/-8qtH 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 - https://www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)
Views: 10368 Caleb Curry
Learn MySQL In Arabic #18 - Constraint - Foreign Key Update, Delete
 
14:22
Learn Foreign Key Options OnUpdate and OnDelete Cascade | Restrict | Set Null | No Action
Views: 8810 Elzero Web School
SQL Null or Empty   How to Check for Null or Empty Column in SQL Server   SQL Training Online
 
03:42
http://www.sqltrainingonline.com SQL Null or Empty - How to Check for Null or Empty Column in SQL Server - SQL Training Online You can download the sample table script at http://www.sqltrainingonline.com/how-to-filter-for-sql-null-or-empty-string/. In this video, I show you how to filter for a SQL null or empty string. It can be difficult to filter a null because you can't simply compare with an equal sign. You have to use a special IS NULL clause to make the filter work. I also show you how to combine both the SQL Null and Empty String together in a special trick with the isnull SQL Server function. I use SQL Server 2012 to demonstrate the technique. Let me know what you think by commenting or sharing on twitter, facebook, google+, etc. If you enjoy the video, please give it a like, comment, or subscribe to my channel. You can visit me at any of the following: SQL Training Online: http://www.sqltrainingonline.com Twitter: http://www.twitter.com/sql_by_joey Google+: https://plus.google.com/#100925239624117719658/posts LinkedIn: http://www.linkedin.com/in/joeyblue Facebook: http://www.facebook.com/sqltrainingonline
Views: 13748 Joey Blue
114. ON DELETE SET NULL in SQL (Hindi)
 
05:15
Please Subscribe Channel Like, Share and Comment Visit : www.geekyshows.com
Views: 3197 Geeky Shows
NULL Value in Oracle Database | Oracle Tutorials for Beginners
 
03:18
NULL Value in Oracle Database | Oracle Tutorials for Beginners NULL Value in Oracle Database NULL Value in Oracle SQL NULL Value in SQL NULL Value in Oracle Database Oracle Tutorials for Beginners Oracle Tutorials for Beginners Oracle PL/SQL Tutorials for Beginners Oracle PL/SQL Tutorials for Beginners Oracle PL/SQL Tutorials for Beginners how to select null values in oracle oracle compare null values in where clause null=null in oracle how to handle null in case statement in oracle how to check null value in oracle stored procedure oracle nvl null value in oracle query how to check empty column value in oracle how to select null values in oracle oracle is null vs = null oracle nvl oracle is not null oracle decode oracle isnull oracle case when null select null from table in oracle oracle compare null values in where clause oracle select null how to check empty column value in oracle oracle sql not null or empty oracle is not null how to handle null in case statement in oracle oracle isnull oracle nvl
Views: 172 Oracle PL/SQL World
T SQL Lesson13 ON DELETE,ON UPDATE CASCADE/ NO ACTION/ SET NULL/ SET DEFAULT Bhaskar Reddy
 
36:01
Jamie King of Neumont University showing the differences between CASCADE, SET DEFAULT, NO ACTION with foreign keys. Komplette Liste der Videos und zusätzliches Material auf Informatik, Uni Saarland: Bachelor: . Now, what happens when you have successfully created a reference, and now you try deleting the parent? This is where the ON DELETE clause comes in.
Views: 46 Trenton Kim
Java: JPA + Hibernate – 19. ON DELETE SET NULL
 
07:34
Suscríbete y sígueme por Twitter ► https://twitter.com/danirod93 Pide ayuda o charla en Discord ► https://makigas.es/discord ¿Cómo replicar una cascada de este tipo en Hibernate? Como tal Hibernate no la ofrece. Si tenemos acceso a la base de datos lo suyo sería establecer manualmente la cascada para que cuando se borre un elemento, sus claves foráneas se pongan a NULL. O, manualmente nullificar las filas antes de borrarlas. ► BIENVENIDO A MAKIGAS En makigas encontrarás tutoriales de programación, desarrollo de juegos y más, gratis y en castellano. Si este vídeo te fue útil, recuerda darle un like, y suscribirte para no perderte más vídeos como éste. ► ENLACES IMPORTANTES ¡Suscríbete ya! http://go.makigas.es/makigas Todos los vídeos en: http://www.makigas.es Twitter: https://twitter.com/makigas Facebook: https://facebook.com/makigas Comunidad: http://facebook.com/groups/makigas ► LEGAL THINGY Música de fondo: Blipotron, por Kevin MacLeod. CC BY 3.0 https://incompetech.com/music/royalty-free/index.html?isrc=USUAN1100514
Views: 3972 makigas
ON DELETE CLAUSE OF FOREIGN KEY CONSTRAINT IN ORACLE SQL WITH EXAMPLE (CASCADE/SET NULL/NO ACTION)
 
15:31
This is a free video tutorial explaining about the nonmandatory on delete clause in the foreign key constraint in Oracle SQL database, the video explains about how the on delete set null and on delete cascade works, how it can be implemented with easy to understand examples. We have also shown practical demonstration on creating the foreign key constraint, and then deleting the data from the parent table and observing the changes that take place in the child table.
Views: 1137 Kishan Mashru
NULL values in DBMS...how to insert null value in table in sql
 
02:07
how to insert null value in table in sql -~-~~-~~~-~~-~- Please watch: "हँसी नहीं रोक पाओगे 100% Guarantee | Indian Funny Videos | Whatsapp Funny Videos😀😀" https://www.youtube.com/watch?v=kbwh5NwXQYo -~-~~-~~~-~~-~- #sqltutorial#oracletutorial#databasetutorial
Views: 1086 Viral Fun Tube
T SQL Lesson13 ON DELETE,ON UPDATE CASCADE/ NO ACTION/ SET NULL/ SET DEFAULT Bhaskar Reddy
 
35:36
Jamie King of Neumont University showing the differences between CASCADE, SET DEFAULT, NO ACTION with foreign keys. Komplette Liste der Videos und . Jamie King of Neumont University showing the differences between CASCADE, SET DEFAULT, NO ACTION with foreign keys. 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 .
Views: 32 Allison Ernest
ADD ROW by using INSERT INTO and having one NULL value,
 
03:35
I am inserting a new row with my information and giving my cell phone number as a null value. Afterwards I use the DELETE statement to remove the row I added
Views: 872 Roger Perez
MySQL - How to Change Null Values to 0 in SQL
 
00:51
Get Source Code/Read : http://intactabode.com/ For Developing support email your Details at : [email protected] Install Free Trail GST Ready Accounting Package Send your Contact information Name, Email, Contact Number to email : [email protected] watch demo in English : https://www.youtube.com/watch?v=a4sFNtZuYzs&ab_channel=IntactAbode watch demo in Hindi : https://www.youtube.com/watch?v=I3eCieDpG3o&ab_channel=IntactAbode Website : http://relybill.com/ Watch More Frequently Used Sql Queries in all Databases Complete Playlist: https://www.youtube.com/playlist?list=PLErD1cRL87W992bgZ_TX7gxl5UKuP9yF9 In this videos i show how to update your null values to zero or o in sql, if you wanted change all the null values in your sql to numerical zero 0, this syntax will sure help you to solve the problem. in some cases i you wanted to display your null values to 0 in sql, mysql, oracle or any other jdbc database this querry will sure help you solve the problem in sql syntax. For Source Code Visit : http://corneey.com/wJ6X2K Subscribe to YouTube channel http://corneey.com/wJ6VoC Like us on Facebook http://corneey.com/wJ6C2l Follow us on Twitter http://corneey.com/wJ6C7x Follow me on Google+ http://corneey.com/wJ6Vhc linkedin http://corneey.com/wJ6V5g
Views: 1949 Intact Abode
MySql basic querries - show, create, select, insert, delete, update, alter, drop, truncate
 
11:43
1) show databases 2) create database thewayur 3) use thewayur 4) show tables 5) create table nishu( id int(3) auto_increment primary key, name varchar(20) not null, age int(3)) 6) select *from nishu 7) insert into nishu (name,age) values('varun',21) 8) Update nishu set name ="sanjay" where id =2 9) delete from nishu where name ="varun" 10) alter table nishu add password varchar(16) not null 11) alter table nishu drop password 12) truncate table nishu 13) drop table nishu 14) drop database thewayur
Views: 19386 Nishu Fun - Gif Game
Null: Databases for Developers #10
 
07:42
The null value represents missing or unknown information. But using it brings complications to your SQL. In this video Chris discusses how to work with null to ensure you get the correct results. Further reading: Oracle Database SQL Reference on Nulls: http://docs.oracle.com/database/122/SQLRF/Nulls.htm#SQLRF30037 Null related functions: http://docs.oracle.com/database/122/SQLRF/Single-Row-Functions.htm#SQLRF51187 Is null condition: http://docs.oracle.com/database/122/SQLRF/Null-Conditions.htm#SQLRF52152 Need help with SQL? Ask us over on AskTOM: https://asktom.oracle.com Twitter: https://twitter.com/ChrisRSaxon Daily SQL Twitter tips: https://twitter.com/SQLDaily All Things SQL blog: https://blogs.oracle.com/sql/ ============================ The Magic of SQL with Chris Saxon Copyright © 2015 Oracle and/or its affiliates. Oracle is a registered trademark of Oracle and/or its affiliates. All rights reserved. Other names may be registered trademarks of their respective owners. Oracle disclaims any warranties or representations as to the accuracy or completeness of this recording, demonstration, and/or written materials (the “Materials”). The Materials are provided “as is” without any warranty of any kind, either express or implied, including without limitation warranties or merchantability, fitness for a particular purpose, and non-infringement.
Views: 1804 The Magic of SQL
13.52 ON DELETE NO ACTION, SET NULL, CASCADE, SET DEFAULT
 
09:23
Komplette Liste der Videos und zusätzliches Material auf http://datenbankenlernen.de Informatik, Uni Saarland: Bachelor: http://www.cs.uni-saarland.de/index.php?id=52&L=1&source=1352 Master: http://www.cs.uni-saarland.de/index.php?id=132&L=1&source=1352 Ph.D./Grad School: http://gradschool.cs.uni-saarland.de/&source=1352
The SQL UPDATE Statement
 
03:44
This video tutorial covers how to update fields in a SQL database table, using the SQL UPDATE statement. More guides and tutorials: http://www.itgeared.com/.
Views: 30404 itgeared
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: 62943 kudvenkat
How to Create Foreign Key Constraint with ON DELETE SET NULL Option in SQL Server -SQL Server P81
 
03:50
SQL Server / T-SQL Tutorial Scenario: You are working as SQL Server developer, you need to create two tables with Primary -Foreign Key Relationship. You want to create Foreign Key Constraint with setting if record will be deleted from Referenced Table (Primary Key Column Table), it should not be deleted from Parent Table ( Foreign Key Constraint Table) instead the value should be updated to Null. Link to scripts used in SQL Server / TSQL Tutorial Video http://www.techbrothersit.com/2016/04/how-to-create-foreign-key-constraint_95.html Check out our website for Different SQL Server, MSBI tutorials and interview questions such as SQL Server Reporting Services(SSRS) Tutorial SQL Server Integration Services(SSIS) Tutorial SQL Server DBA Tutorial SQL Server / TSQL Tutorial ( Beginner to Advance) http://www.techbrothersit.com/
Views: 774 TechBrothersIT
SQL CASCADE, SET DEFAULT, NO ACTION
 
05:50
Jamie King of Neumont University showing the differences between CASCADE, SET DEFAULT, NO ACTION with foreign keys.
Views: 10377 Jamie King
Insert and Commit: Databases for Developers #7
 
04:51
You load data into your database tables with an insert statement. In this episode Chris discusses how to use single and multirow inserts and their pros and cons. He also covers how to persist your changes to the database with commit. See the full syntax for insert in the SQL reference guide: http://docs.oracle.com/database/122/SQLRF/INSERT.htm#SQLRF01604 Take the Databases for Developers FREE SQL course at https://devgym.oracle.com/devgym/database-for-developers.html Need help with SQL? Ask us over on AskTOM: https://asktom.oracle.com Twitter: https://twitter.com/ChrisRSaxon Daily SQL Twitter tips: https://twitter.com/SQLDaily All Things SQL blog: https://blogs.oracle.com/sql/ ============================ The Magic of SQL with Chris Saxon Copyright © 2015 Oracle and/or its affiliates. Oracle is a registered trademark of Oracle and/or its affiliates. All rights reserved. Other names may be registered trademarks of their respective owners. Oracle disclaims any warranties or representations as to the accuracy or completeness of this recording, demonstration, and/or written materials (the “Materials”). The Materials are provided “as is” without any warranty of any kind, either express or implied, including without limitation warranties or merchantability, fitness for a particular purpose, and non-infringement.
Views: 3991 The Magic of SQL
SQL tutorial 32: How To Insert Data into a Table Using SQL Developer
 
05:16
SQL Tutorial 32 How To Insert Data into a Table Using SQL Developer and How to delete Data/Row From a table. Website : http://www.RebellionRider.com New Series of #SQL tutorial on How to Insert Data. I'll cover all the traditional way along with some tips and tricks on Data insertion. Keep watching and enjoy #SQLing Copy Cloud referral link || Use this link to join copy cloud and get 20GB of free storage https://copy.com?r=j7eYO7 Amazon Wishlist: http://bit.ly/wishlist-amazon Contacts E-Mail [email protected] Twitter https://twitter.com/rebellionrider Instagram http://instagram.com/rebellionrider Facebook. https://www.facebook.com/imthebhardwaj Linkedin. http://in.linkedin.com/in/mannbhardwaj/ Thanks for liking, commenting, sharing and watching more of our videos This is Manish from www.RebellionRider.com
Views: 44808 Manish Sharma
MySQL - Insert Null in Database
 
01:58
Get Source Code/Read : http://intactabode.com/ For Developing support email your Details at : [email protected] Install Free Trail GST Ready Accounting Package Send your Contact information Name, Email, Contact Number to watch demo in English : https://www.youtube.com/watch?v=a4sFNtZuYzs&ab_channel=IntactAbode watch demo in Hindi : https://www.youtube.com/watch?v=I3eCieDpG3o&ab_channel=IntactAbode For Source Code Visit : http://corneey.com/wJ6X2K Subscribe to YouTube channel http://corneey.com/wJ6VoC Like us on Facebook http://corneey.com/wJ6C2l Follow us on Twitter http://corneey.com/wJ6C7x Follow me on Google+ http://corneey.com/wJ6Vhc linkedin http://corneey.com/wJ6V5g Watch More Frequently Used Sql Queries in all Databases Complete Playlist: https://www.youtube.com/playlist?list=PLErD1cRL87W992bgZ_TX7gxl5UKuP9yF9 how to insert null value in mysql how to update null value in sql how to insert null value in sql using c# how to insert null value in sql server 2008 sql insert null date how to insert null value in oracle how to insert null value in integer field in sql server how to insert blank value in sql
Views: 1776 Intact Abode
SQL tutorial 19: ON DELETE SET NULL clause of Foreign Key By Manish Sharma (RebellionRider)
 
07:44
SQL Tutorial 19 : ON DELETE SET NULL foreign key Clause. Links used in the tutorial On delete set null website article [ download SQL script from same link] : http://www.rebellionrider.com/on-delete-set-null.htm Foreign Key Tutorial Video : http://youtu.be/0nbkBI5r3Gw Foreign Key Tutorial Blog : http://www.rebellionrider.com/sql-foreign-key.htm This video is the part of foreign key video In this sql tutorial you will learn the referential clause ON DELETE SET NULL of foreign key. On Delete Set null clause guarantee the relation integrity in foreign key/ Tool used in this tutorial is SQL Developer. This tutorial series is part of SQL expert exam certification training. if you are preparing for SQL certification you can use my tutorials. This SQL Tutorial is a part of free training. Copy Cloud referral link || Use this link to join copy cloud and get 20GB of free storage https://copy.com?r=j7eYO7 Contacts E-Mail [email protected] Twitter https://twitter.com/rebellionrider Instagram http://instagram.com/rebellionrider Facebook. https://www.facebook.com/imthebhardwaj Linkedin. http://in.linkedin.com/in/mannbhardwaj/ Thanks for liking, commenting, sharing and watching more of our videos This is Manish from RebellionRider.com
Views: 45211 Manish Sharma
Oracle SQL Tutorial 18 - How to Create Foreign Keys
 
07:09
In this video we are going to be creating foreign keys. I highly recommend watching the previous video before you watch this one. Essentially, we are creating a very simple database for a system where we can create projects and add people to those projects. We started with the users table: --Delete the table if needed: --DROP TABLE users; CREATE TABLE users( user_id NUMBER, username VARCHAR2(50 CHAR) UNIQUE, CONSTRAINT users_pk PRIMARY KEY (user_id) ); Now we are going to create a table for projects with a column that is a foreign key to the username. We're going to want to make this match data types: CREATE TABLE projects( project_id NUMBER, project_name VARCHAR2(50 CHAR) UNIQUE, creator VARCHAR2(50 CHAR) ) Next, we need to add the column attributes we decided on last video: CREATE TABLE projects( project_id NUMBER, project_name VARCHAR2(50 CHAR) UNIQUE, creator VARCHAR2(50 CHAR) NOT NULL ) NOT NULL because we want every project to have a creator, but we are not labeling UNIQUE because that means we could only have a specific username once in the table. We want to allow a user to create multiple projects. We also need to add a primary key: CREATE TABLE projects( project_id NUMBER, project_name VARCHAR2(50 CHAR) UNIQUE, creator VARCHAR2(50 CHAR) NOT NULL, CONSTRAINT projects_pk PRIMARY KEY (username) ) Now, the question that remains is, how can I tell Oracle that I want the username to reference the username column of the other table? We have to make a foreign key constraint. As you've learned from the previous videos, there are about three ways to create constraints. You can do it inline at the column level, unnamed. You can do it at the column level, named, and you can do it at the Table level, named. Usually the table-level is preferred, but I will quickly remind you how to do all three again. CREATE TABLE projects( project_id NUMBER, project_name VARCHAR2(50 CHAR) UNIQUE, creator VARCHAR2(50 CHAR) NOT NULL REFERENCES users (username), CONSTRAINT projects_pk PRIMARY KEY (project_id) ) This works, but if we want to name it, we should do this: CREATE TABLE projects( project_id NUMBER, project_name VARCHAR2(50 CHAR) UNIQUE, creator VARCHAR2(50 CHAR) NOT NULL CONSTRAINT projects_users_fk REFERENCES users (username), CONSTRAINT projects_pk PRIMARY KEY (project_id) ) This works, but the preferred method is to do it at the table level: 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) ) Great! So you've learned how to create a foreign key, now we can see it inside of Oracle SQL Developer. One important thing when it comes to foreign keys is what happens when have data in your database and you try to delete the parent row that a row in the child table references? In the next video we are going to configure that using ON DELETE. See you all then and if you enjoy this series, please do me a huge favor by liking the video and subscribing to my YouTube channel. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ HELP ME! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://eepurl.com/-8qtH 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 - https://www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)
Views: 15145 Caleb Curry
Dynamic SQL in Stored Procedure
 
09:32
In this video we will discuss, using dynamic sql in a stored procedure and it's implications from sql injection perspective. We will discuss performance implications of using dynamic sql in a stored procedure in a later video. Text version of the video http://csharp-video-tutorials.blogspot.com/2017/04/dynamic-sql-in-stored-procedure.html Slides http://csharp-video-tutorials.blogspot.com/2017/04/dynamic-sql-in-stored-procedure_11.html All SQL Server Text Articles http://csharp-video-tutorials.blogspot.com/p/free-sql-server-video-tutorials-for.html All SQL Server Slides http://csharp-video-tutorials.blogspot.com/p/sql-server.html All SQL Server Tutorial Videos https://www.youtube.com/playlist?list=PL08903FB7ACA1C2FB 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 Consider the following stored procedure "spSearchEmployees". We implemented this procedure in Part 139 of SQL Server tutorial. This stored procedure does not have any dynamic sql in it. It is all static sql and is immune to sql injection. Create Procedure spSearchEmployees @FirstName nvarchar(100) = NULL, @LastName nvarchar(100) = NULL, @Gender nvarchar(50) = NULL, @Salary int = NULL As Begin Select * from Employees where (FirstName = @FirstName OR @FirstName IS NULL) AND (LastName = @LastName OR @LastName IS NULL) AND (Gender = @Gender OR @Gender IS NULL) AND (Salary = @Salary OR @Salary IS NULL) End Go Whether you are creating your dynamic sql queries in a client application like ASP.NET web application or in a stored procedure, you should never ever concatenate user input values. Instead you should be using parameters. Notice in the following example, we are creating dynamic sql queries by concatenating parameter values, instead of using parameterized queries. This stored procedure is prone to SQL injection. Let's prove this by creating a "Search Page" that calls this procedure. Create Procedure spSearchEmployeesBadDynamicSQL @FirstName nvarchar(100) = NULL, @LastName nvarchar(100) = NULL, @Gender nvarchar(50) = NULL, @Salary int = NULL As Begin Declare @sql nvarchar(max) Set @sql = 'Select * from Employees where 1 = 1' if(@FirstName is not null) Set @sql = @sql + ' and FirstName=''' + @FirstName + '''' if(@LastName is not null) Set @sql = @sql + ' and LastName=''' + @LastName + '''' if(@Gender is not null) Set @sql = @sql + ' and Gender=''' + @Gender + '''' if(@Salary is not null) Set @sql = @sql + ' and Salary=''' + @Salary + '''' Execute sp_executesql @sql End Go Add a Web Page to the project that we have been working with in our previous video. Name it "DynamicSQLInStoredProcedure.aspx". Copy and paste the HTML and code available on my blog at the following link http://csharp-video-tutorials.blogspot.com/2017/04/dynamic-sql-in-stored-procedure.html At this point, run the application and type the following text in the "Firsname" text and click "Search" button. Notice "SalesDB" database is dropped. Our application is prone to SQL injection as we have implemented dynamic sql in our stored procedure by concatenating strings instead of using parameters. ' Drop database SalesDB -- In the following stored procedure we have implemented dynamic sql by using parameters, so this is not prone to sql injecttion. This is an example for good dynamic sql implementation. Create Procedure spSearchEmployeesGoodDynamicSQL @FirstName nvarchar(100) = NULL, @LastName nvarchar(100) = NULL, @Gender nvarchar(50) = NULL, @Salary int = NULL As Begin Declare @sql nvarchar(max) Declare @sqlParams nvarchar(max) Set @sql = 'Select * from Employees where 1 = 1' if(@FirstName is not null) Set @sql = @sql + ' and [email protected]' if(@LastName is not null) Set @sql = @sql + ' and [email protected]' if(@Gender is not null) Set @sql = @sql + ' and [email protected]' if(@Salary is not null) Set @sql = @sql + ' and [email protected]' Execute sp_executesql @sql, N'@FN nvarchar(50), @LN nvarchar(50), @Gen nvarchar(50), @sal int', @[email protected], @[email protected], @[email protected], @[email protected] End Go On the code-behind page, use stored procedure spSearchEmployeesGoodDynamicSQL instead of spSearchEmployeesBadDynamicSQL. We do not have to change any other code. At this point run the application one more time and type the following text in the "Firstname" textbox and click the "Search" button. ' Drop database SalesDB -- Notice "SalesDB" database is not dropped, So in this case our application is not succeptible to SQL injection attack. Summary : Whether you are creating dynamic sql in a client application (like a web application) or in a stored procedure always use parameters instead of concatnating strings. Using parameters to create dynamic sql statements prevents sql injection.
Views: 23355 kudvenkat
PL/SQL tutorial 16: Table Auditing using DML Triggers in Oracle PL/SQL
 
09:55
Learn Table Auditing using DML Triggers in Oracle Database and Increase the level of security by keep an eye on user tempering your table data. ------------------------------------------------------------------------ ►►►LINKS◄◄◄ Blog : http://bit.ly/table-auditing Previous Tutorial ► DML Triggers with Examples https://youtu.be/-OR7zLzCh_I ► Select-Into Statement: https://youtu.be/F5eMJhwmCQs ►Sysdate Blog : http://bit.ly/sysdate-in-oracle-by-rebellionrider ------------------------------------------------------------------------- ►►►Let's Get Free Uber Cab◄◄◄ Use Referral Code UberRebellionRider and get $20 free for your first ride. ------------------------------------------------------------------------- ►Make sure you SUBSCRIBE and be the 1st one to see my videos! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ►►►Find me on Social Media◄◄◄ Follow What I am up to as it happens on https://twitter.com/rebellionrider https://www.facebook.com/imthebhardwaj http://instagram.com/rebellionrider https://plus.google.com/+Rebellionrider http://in.linkedin.com/in/mannbhardwaj/ http://rebellionrider.tumblr.com/ http://www.pinterest.com/rebellionrider/ You can also Email me at for E-mail address please check About section Please please LIKE and SHARE my videos it makes me happy. Thanks for liking, commenting, sharing and watching more of our videos This is Manish from RebellionRider.com ♥ I LOVE ALL MY VIEWERS AND SUBSCRIBERS
Views: 59440 Manish Sharma
SQL,  How to insert date data type, lesson 14
 
08:23
14th video of the series, learning structured Query Language. How to insert date data type into a column. Using oracle platform.
Views: 38207 hammadshams
SQL Server 17 - ON DELETE and ON UPDATE
 
08:14
Now, what happens when you have successfully created a reference, and now you try deleting the parent? This is where the ON DELETE clause comes in. This is essentially how we configure how strict a foreign key is. There are 4 options you can give for an ON DELETE: Standard SQL Server NO ACTION Yes (Default) CASCADE Yes SET NULL Yes SET DEFAULT Yes Now the default is NO ACTION. This means that when you try to delete a parent row, SQL Server is going to throw an error and not let you. Cascade means that if you delete the parent row, any rows that reference that parent will also be deleted. This is pretty dangerous and not often recommended. SET NULL will set the foreign key to be NULL. Now obviously, this is going to require that the foreign key is not labelled NOT NULL. Finally, set DEFAULT will change the reference to the child row to some default value. We have not discussed defaults, but a column can have a default value. For example, we could make a deleted user in our Users table, and set the default for the foreign key to be the deleted user, and when any other users are deleted it will default to the deleted user UserId. In addition to the ON DELETE clause, there is the ON UPDATE clause. This one is a little less common because it configures what happens when a parent value changes. Obviously, when you are referencing a primary key, the ON UPDATE clause is nearly useless. That's because the primary key value is never supposed to change. If, on the other hand, we have a foreign key referencing a UNIQUE column that is not a primary key, it may change occasionally. So the only times you have to worry about the ON UPDATE clause is with foreign keys referencing UNIQUE columns that are not a primary key, and when you have natural keys that break the rules and actually do change at some point in time. The ON UPDATE clause has the same options as the ON DELETE clause and they all work the same way. Now, the last thing you need to know about foreign keys is that they must match the data type of the column you are referencing. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Support me! http://www.patreon.com/calebcurry Subscribe to my newsletter: http://eepurl.com/-8qtH 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 - https://www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)
Views: 3442 Caleb Curry
SQL tutorials 17: SQL Primary Key constraint,  Drop primary Key
 
09:22
Blog link: http://www.rebellionrider.com/sql-primary-key.htm SQL tutorial on Primary key / SQL Primary key, In this tutorial you will learn about simple primary key, composute primary key, how to drop primary key. defining primary key using create table and alter table along with many other things. Tool used in this tutorial is SQL Developer. This tutorial series is part of SQL expert exam certification training. if you are preparing for SQL certification you can use my tutorials. This SQL Tutorial is a part of free training. Copy Cloud referral link || Use this link to join copy cloud and get 20GB of free storage https://copy.com?r=j7eYO7 Contacts E-Mail [email protected] Twitter https://twitter.com/rebellionrider Instagram http://instagram.com/rebellionrider Facebook. https://www.facebook.com/imthebhardwaj Linkedin. http://in.linkedin.com/in/mannbhardwaj/ Thanks for linking, commenting, sharing and watching more of our videos This is Manish from RebellionRider.com So Primary Key There are two types of Primary keys First is Simple primary Key: Primary key which Involves only one column and Second is Composite Primary Key: Primary Key which involves more than one column. We will start with Simple primary key. You can create Primary key either with Create Table statement of by using Alter table Statement. Let's define simple primary key using create table statements. With create table statement we can either define primary key at column level or at table level. We will start with defining Primary key at column level using create table statement. You just have to put keyword Primary key after data type and size of column while defining a column of a table. Here oracle server will create a primary key on product id with default constraint name which will be slightly difficult to understand. You can give your own name to your constraint which is also a good practice.
Views: 92453 Manish Sharma
Accept Of NULL VALUES IN UNIQUE CONSTRAINT
 
08:05
Can we insert more than one NULL values in Unique constraint?
Views: 157 GI Tech
SQL tutorials 20: On Delete Cascade Foreign Key By Manish Sharma (RebellionRider)
 
05:55
Oracle Database 11g Tutorial 20: On delete cascade This tutorial will show you how to define foreign key with on delete cascade clause. Links Blog: http://www.rebellionrider.com/on-delete-cascade.htm SQL Tutorial 19 On delete set Null: http://www.rebellionrider.com/on-delete-cascade.htm SQL Tutorial 19 Foreign Key: http://youtu.be/0nbkBI5r3Gw Copy Cloud referral link || Use this link to join copy cloud and get 20GB of free storage https://copy.com?r=j7eYO7 Tool used in this tutorial is SQL Developer. This tutorial series is part of SQL expert exam certification training. if you are preparing for SQL certification you can use my tutorials. This SQL Tutorial is a part of free training. Contacts E-Mail [email protected] Twitter https://twitter.com/rebellionrider Instagram http://instagram.com/rebellionrider Facebook. https://www.facebook.com/imthebhardwaj Linkedin. http://in.linkedin.com/in/mannbhardwaj/ Thanks for liking, commenting, sharing and watching more of our videos This is Manish from RebellionRider.com
Views: 42071 Manish Sharma
Oracle Using In , Between and Not تعليم أوراكل
 
10:27
by Mohamed El Desouki - محمد الدسوقى [email protected] Tel :00966 553450836 جامعة سلمان بن عبد العزيز - السعودية - الخرج How to use In , Between and Not. 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 insert into statement update statement delete statement select statement basic query where clause select where Like '%' Like '_' select where Like select where Between Between , Not Between select where In , Not In
Part 2   SQL query to get organization hierarchy
 
10:14
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/05/part-2-sql-query-to-get-organization.html To get the best out of this video, the following concepts need to be understood first. These are already discussed in SQL Server Tutorial. 1. Self-Join - http://www.youtube.com/watch?v=qnYSN_7qwgg 2. CTE - http://www.youtube.com/watch?v=ZXB5b-7HJHk 3. Recursive CTE - http://www.youtube.com/watch?v=GGoV0wTMCg0 Here is the problem definition: 1. Employees table contains the following columns a) EmployeeId, b) EmployeeName c) ManagerId 2. If an EmployeeId is passed, the query should list down the entire organization hierarchy i.e who is the manager of the EmployeeId passed and who is managers manager and so on till full hierarchy is listed. For example, Scenario 1: If we pass David's EmployeeId to the query, then it should display the organization hierarchy starting from David. Scenario 2: If we pass Lara's EmployeeId to the query, then it should display the organization hierarchy starting from Lara. We will be Employees table for this demo. SQL to create and populate Employees table with test data Create table Employees ( EmployeeID int primary key identity, EmployeeName nvarchar(50), ManagerID int foreign key references Employees(EmployeeID) ) GO Insert into Employees values ('John', NULL) Insert into Employees values ('Mark', NULL) Insert into Employees values ('Steve', NULL) Insert into Employees values ('Tom', NULL) Insert into Employees values ('Lara', NULL) Insert into Employees values ('Simon', NULL) Insert into Employees values ('David', NULL) Insert into Employees values ('Ben', NULL) Insert into Employees values ('Stacy', NULL) Insert into Employees values ('Sam', NULL) GO Update Employees Set ManagerID = 8 Where EmployeeName IN ('Mark', 'Steve', 'Lara') Update Employees Set ManagerID = 2 Where EmployeeName IN ('Stacy', 'Simon') Update Employees Set ManagerID = 3 Where EmployeeName IN ('Tom') Update Employees Set ManagerID = 5 Where EmployeeName IN ('John', 'Sam') Update Employees Set ManagerID = 4 Where EmployeeName IN ('David') GO Here is the SQL that does the job Declare @ID int ; Set @ID = 7; WITH EmployeeCTE AS ( Select EmployeeId, EmployeeName, ManagerID From Employees Where EmployeeId = @ID UNION ALL Select Employees.EmployeeId , Employees.EmployeeName, Employees.ManagerID From Employees JOIN EmployeeCTE ON Employees.EmployeeId = EmployeeCTE.ManagerID ) Select E1.EmployeeName, ISNULL(E2.EmployeeName, 'No Boss') as ManagerName From EmployeeCTE E1 LEFT Join EmployeeCTE E2 ON E1.ManagerID = E2.EmployeeId
Views: 247803 kudvenkat
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://eepurl.com/-8qtH 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 - https://www.dreamhost.com/r.cgi?1487063 (The best web hosting for a cheap price!)
Views: 6351 Caleb Curry
HeidiSQL - Insert NULL values on data grid
 
00:21
To insert a NULL value on the HeidiSQL datagrid: 1. select a column with NULL data 2. Copy the NULL data 3. Paste the NULL data as many times as you want
Views: 1825 Webspicer
Oracle SQL PLSQL 12C Tutorial 19 - Default Value
 
04:32
This Video Tutorial Will Describe how to set the default value of the column. This 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. DEFAULT clause is used to set the value for the table column. DEFAULT clause insert the predefined value into the column if you left it blank while inserting the column. Full Syntax will be given in this video tutorial about how to use the DEFAULT clause. Along with live example to demonstrate DEFAULT clause. All the keywords, format, mandatory clauses etc are described in this video.
mysql tutorial for beginners (7/8) : Foreign Keys (FK) & Joins
 
08:00
mysql tutorial for beginners (7/8) : Foreign Keys (FK) & Join Foreign key relationships involve a parent table that holds the central data values, and a child table with identical values pointing back to its parent. The FOREIGN KEY clause is specified in the child table. The parent and child tables must use the same storage engine. Corresponding columns in the foreign key and the referenced key must have similar data types. The size and sign of integer types must be the same. Now, we can say: MySQL supports foreign keys, which let you cross-reference related data across tables, and foreign key constraints, which help keep this spread-out data consistent. How Foreign keys help guarantee referential integrity? For storage engines supporting foreign keys, MySQL rejects any INSERTor UPDATE operation that attempts to create a foreign key value in a child table if there is no a matching candidate key value in the parent table. When an UPDATE or DELETE operation affects a key value in the parent table that has matching rows in the child table, The result depends on the referential action specified using ON UPDATE and ON DELETE subclauses of the FOREIGN KEY clause. MySQL supports 4 options regarding the action to be taken: CASCADE: Delete or update the row from the parent table, and automatically delete or update the matching rows in the child table. SET NULL: Delete or update the row from the parent table, and set the foreign key column or columns in the child table to NULL. If you specify a SET NULL action, make sure that you have not declared the columns in the child table as NOT NULL. RESTRICT: Rejects the delete or update operation for the parent table. NO ACTION: A keyword from standard SQL. In MySQL, equivalent to RESTRICT. The MySQL Server rejects the delete or update operation for the parent table if there is a related foreign key value in the referenced table. For an ON DELETE or ON UPDATE that is not specified, the default action is always RESTRICT. FK constraint can be added using CREATE TABLE or ALTER TABLE statement First off let’s create the parent tables, I’ll begin with Tests table: CREATE TABLE Tests ( id_test INT NOT NULL AUTO_INCREMENT, title VARCHAR(25) NOT NULL, date DATE NOT NULL, PRIMARY KEY(id_test) ); And Questions table: CREATE TABLE Questions ( id_question INT NOT NULL AUTO_INCREMENT, question TEXT NOT NULL, answer TEXT NOT NULL, PRIMARY KEY(id_question) ); Now, let’s create the child table, Question_in_test: Id_test column will be FK reference to the id_test in Tests table, don’t forget both columns should be the same data types, and same size, id_question column will be FK reference to the id_question in Questions table, CREATE TABLE Question_in_test ( id_qt INT NOT NULL AUTO_INCREMENT, number TINYINT NOT NULL, value TINYINT NOT NULL, id_test INT, id_question INT, FOREIGN KEY(id_test) REFERENCES Tests(id_test) ON DELETE RESTRICT ON UPDATE CASCADE, FOREIGN KEY(id_question) REFERENCES Questions(id_question) ON DELETE NO ACTION ON UPDATE CASCADE, PRIMARY KEY(id_qt) ); The last child table is the Grade_per_question This table contains 2 FKs Id_student FK reference to the id_student in Students table, And id_question per test reference to the id question per test in Question_in_test table, ALTER TABLE grade_per_question ADD FOREIGN KEY(id_qt) REFERENCES Question_in_test(id_qt) ON DELETE NO ACTION ON UPDATE CASCADE, FOREIGN KEY(id_student) REFERENCES Students(id_student) ON DELETE RESTRICT ON UPDATE CASCADE, If you wish to specify the column on which to join two tables, use the JOIN ON construct: Students table joined with grade_per_question on id_student And grade_per_question joined with question_in_test on id_qt Question_in_test joined with tests on id_test: SELECT name,title,date,sum(grade) FROM students join grade_per_question on students.id_student = grade_per_question.id_student join question_in_test on question_in_test.id_qt = grade_per_question.id_qt join tests on tests.id_test = question_in_test.id_test Whatever kind of data you are storing in your database, it must have some value to you, therefore, it’s important that you keep backups, to protect your investment also, there will be times when you have to migrate your database over to a new server, in the next tutorial we will learn how to make backing up and restoring data in mysql. Subscribe for more: ---------------------------------------------------------------------------- https://www.youtube.com/subscription_center?add_user=saf3al2a SWE.Safaa Al-Hayali - saf3al2a
Views: 23808 Safaa Al-Hayali
SQL with Oracle 10g XE - Using ALTER TABLE to Modify Table Columns
 
05:23
In this video I use the ALTER TABLE command to modify an existing field column. The command will allow you to change the data types, whether the field can be null, or even the primary key. When using the ALTER TABLE command you would use the keyword MODIFY to make changes to an existing column. Be careful when changing a data type of the null field as existing data may cause an error if not in compliance with the new change. The code I used to alter the Books table is : ALTER TABLE BOOKS MODIFY ISBN_10 VARCHAR(13); This video is part of a series of videos with the purpose of learning the SQL language. For more information visit Lecture Snippets at http://lecturesnippets.com.
Views: 14818 Lecture Snippets
4- Oracle DB - Primary Foreign Unique Not Null Check Composite Keys Table Level and Column Level.avi
 
37:25
Oracle DB - Primary Foreign Unique Not Null Check Composite Keys Table Level and Column Level
Views: 2599 Adel Sabour
Base de datos #11 | Modificar datos (Update)
 
14:14
En este vídeo aprenderemos a modificar datos de una tabla mediante la sentencia update, también aprenderemos a juntarla con un where y un from para poder ser más específicos en nuestra actualización. No olvides suscribirte para tomar todos los cursos que estaremos impartiendo Visita nuestro canal: http://bit.ly/CodigoCompilado Nuestras redes sociales: Twitter: https://twitter.com/CodigoCompilado Facebook: http://bit.ly/CodigoCompiladoFacebook Correo: [email protected] ******************************************************* create database modificar use modificar create table producto( clave_prod int, nom_prod varchar(20), precio float, constraint pk_cp primary key (clave_prod)) create table cliente( clave_clie int, nom_clie varchar(20), constraint pk_cc primary key (clave_clie)) create table nota( folio int, clave_prod1 int, clave_clie1 int, cant int, subtot float, constraint fk_cp1 foreign key (clave_prod1) references producto (clave_prod), constraint fk_cc1 foreign key (clave_clie1) references cliente (clave_clie)) insert into producto values (1,'papas',7) insert into producto values (2,'refresco',9) insert into cliente values (1,'ana') insert into cliente values (2,'sergio') insert into nota values (1,1,1,4,null) insert into nota values (2,2,2,1,null)
Views: 40660 CodigoCompilado
Learn Oracle | How to Alter a Table using SQL
 
04:53
Pebbles present, Learn Oracle 10g with Step By Step Video Tutorials. Learn Oracle 10g Tutorial series contains the following videos : Learn Oracle - History of Oracle Learn Oracle - What is Oracle - Why do we need Oracle Learn Oracle - What is a Database Learn Oracle - What is Grid Computing Learn Oracle - What is Normalization Learn Oracle - What is ORDBMS Learn Oracle - What is RDBMS Learn Oracle - Alias Names, Concatenation, Distinct Keyword Learn Oracle - Controlling and Managing User Access (Data Control Language) Learn Oracle - Introduction to SQL Learn Oracle - Oracle 10g New Data Types Learn Oracle - How to Alter a Table using SQL Learn Oracle - How to Create a Package in PL SQL Learn Oracle - How to Create a Report in SQL Plus Learn Oracle - How to Create a Table using SQL - Not Null, Unique Key, Primary Key Learn Oracle - How to Create a Table using SQL Learn Oracle - How to Create a Trigger in PL SQL Learn Oracle - How to Delete Data from a Table using SQL Learn Oracle - How to Drop and Truncate a Table using SQL Learn Oracle - How to Insert Data in a Table using SQL Learn Oracle - How to open ISQL Plus for the first time Learn Oracle - How to Open SQL Plus for the First Time Learn Oracle - How to Update a Table using SQL Learn Oracle - How to use Aggregate Functions in SQL Learn Oracle - How to use Functions in PL SQL Learn Oracle - How to use Group By, Having Clause in SQL Learn Oracle - How to Use Joins, Cross Join, Cartesian Product in SQL Learn Oracle - How to use Outer Joins (Left, Right, Full) in SQL Learn Oracle - How to use the Character Functions, Date Functions in SQL Learn Oracle - How to use the Merge Statement in SQL Learn Oracle - How to use the ORDER BY Clause with the Select Statement Learn Oracle - How to use the SELECT Statement Learn Oracle - How to use the Transactional Control Statements in SQL Learn Oracle - How to use PL SQL Learn Oracle - Data Types in PL SQL Learn Oracle - Exception Handling in PL SQL Learn Oracle - PL SQL Conditional Logics Learn Oracle - PL SQL Cursor Types - Explicit Cursor, Implicit Cursor Learn Oracle - PL SQL Loops Learn Oracle - Procedure Creation in PL SQL Learn Oracle - Select Statement with WHERE Cause Learn Oracle - SQL Operators and their Precedence Learn Oracle - Using Case Function, Decode Function in SQL Learn Oracle - Using Logical Operators in the WHERE Clause of the Select Statement Learn Oracle - Using Rollup Function, Cube Function Learn Oracle - Using Set Operators in SQL Learn Oracle - What are the Different SQL Data Types Learn Oracle - What are the different types of Databases Visit Pebbles Official Website - http://www.pebbles.in Subscribe to our Channel – https://www.youtube.com/channel/UCNNjWVsQqaMYccY044vtHJw?sub_confirmation=1 Engage with us on Facebook at https://www.facebook.com/PebblesChennai Please Like, Share, Comment & Subscribe
Views: 143 Pebbles Tutorials
23- Constraint Part8 ForeignKey With Options
 
25:11
Constraint Foreign Key With Options -------------------------------------------------------------- 1- on delete no action 2- on delete set null 3- on delete set default 4- on delete cascade 5- on delete set null on update cascade ----------------------------------------­---------------------------- أرجوا لو الفيديو عجبك تضغط أعجبني --- ولو في أي تعليق ممكن تبعتلي وشكرا
Views: 200 sayed hawas