How to set Check constraints,Default constraints through query

Published: 20 October 2023
on channel: Sql Query for jobs
18
0

How to set Check constraints,Default constraints through query.

Table Scripts:

Create Table Employee
(
EmpId int primary key,
Name varchar(100) not null,
Age int check(age between 18 and 50),
JoinDate datetime default getdate()
)

--Allowed
insert into Employee values(1,'Arjun',25,'2020-08-28')

--Not allowed age less than18
insert into Employee values(2,'Kumar',17,'2021-03-15')
--Not allowed age greater than 50
insert into Employee values(2,'Kumar',51,'2021-03-15')

select * from Employee

--Default constraints -Not passing the joining date it will insert default values
insert into Employee(EmpId,Name,Age) values(2,'Kumar',35)

--default will allow null values

insert into Employee values(3,'Sara',35,null)


Sql Query for jobs
#   / @sqlqueryforjobs  


Playlists:

   • SQL Query Interview Questions  

   • Stored Procedure in sql  

   • Sql Basics Through Query  

   • User Defined Functions in sql  

   • Build in functions in sql  

   • Views in sql  

Sql Basics Links:
   • How to create,alter,drop a Table thro...  
   • Group by statement and Having clause ...  
   • Aggregate functions in Sql Server|Cou...  
   • How to set Identity column through query  
   • How to get the last identity inserted...  
   • How to create User Defined Datatypes ...  
   • How to create User Defined Table type...  
   • How to create schema and create table...  
   • How to transfer one schema object to ...  
   • null values in sql  
   • Derived tables in sql |Sql Server|  
   • Over clause in Sql |Sql Server|  

Constraints Links:

   • How to set primary key constraints th...  
   • How to set foreign key constraints th...  
   • How to set Unique Key constraints,Not...  
   • How to set Check constraints,Default ...  
   • Cascading Referential Integrity Const...  

set operators Links:
   • Union ,Union All in Sql |Sql Server|S...  
   • Intersect ,Except in Sql(Set Operators)  

Real time joins scenarios Links:
   • Real time scenario on Inner join in sql  
   • Real time scenario on Left join in Sql  
   • Real time scenario on Right join in Sql  
   • Full join/Full outer join in Sql  
   • Real time scenario on Cross  join in ...  

Temp Tables Links:
   • How to create Temporary tables in sql  
   • How to set Constraints in Temporary t...  

Table Variables Links:
   • Table variable in sql  
   • How to set constraints in Table varia...  

SubQuery Links:
   • Subquery In SQL |SQL Tutorial For Beg...  
   • Correlated Subquery In SQL |SQL Basics|  

Build in Functions Links:
   • STRING_AGG() in sql  
   • STRING_SPLIT in sql.  
   • Coalesce function in sql |Sql Server|.  


Cte Links:
   • CTE  in sql.| Common Table Expression|  
   • CTE using multiple tables/multiple CT...  
   • How to insert,update,delete data usin...  
   • Recursive CTE in sql.| Recursive Comm...  

Views Links:
   • Views in sql  
   • How to insert,update,delete data thro...  
   • SQL Views, WITH CHECK OPTION  
   • How to update meta data of views in sql  
   • SCHEMABINDING option in sql views.  

Stored procedure Links:
   • How to create,alter,drop a stored pro...  
   • How to create a stored procedure with...  
   • Optional Parameter Stored Procedure i...  
   • How to Encrypt stored procedure  in S...  
   • Return value of stored procedure in S...  
   • stored procedure summary in sql.  
   • How to use User defined Table type in...  
   • How to use Temp Tables in Stored Proc...  

User Defined Functions Link:
   • User Defined  Scalar Functions  in sq...  
   • Inline table valued function in sql |...  
   • Multi-Statement Table Valued Function...  
   • How to insert,update,delete datas to ...  
   • How to use User defined Table type in...  
   • How to set SchemaBinding in User defi...  

Sql Query Interview Questions Link:

   • Write a query to find the stock of ea...  
   • Write a query to fetch the employees ...  
   • Write a Query to Get  Largest Sold Pr...  
   • Write a Query to find Diffrence of ea...  
   • How to delete duplicate records in sq...  
   • Write a query to merge source table d...  
   • Write a query to display two column v...  
   • Write a query to display converts the...  
   • Write a query to generate cricket tou...  
   • Write a Procedure to Get display Tabl...  


Constraints in Sql Server,Check constraints,default constraints,Sql,Sql Server,Mssql,check,default,contraints

#sql #sqlserver #sqlab #sqlinjection #mssql #sqldeveloper #sqlsaturday
#sql #programming #database #sqlserver #coding #developer #programmer #software #datascience #code #computerscience #data #dataanalytics
#technology #computer #development #bigdata #backend #coder #codinglife #microsoft #sqldatabase #softwaredeveloper #informationtechnology #programminglife #softwaredevelopment #programmerslife #sqlforbeginners #sqltraining #sqlinterviewquestions #mssqlserver


Watch video How to set Check constraints,Default constraints through query online without registration, duration hours minute second in high quality. This video was added by user Sql Query for jobs 20 October 2023, don't forget to share it with your friends and acquaintances, it has been viewed on our site 18 once and liked it 0 people.