Skip to main content

Posts

Showing posts with the label unique

SQL insert query validation constraints to limit number of records

This is sample of query for  SQL insert query validation constraints to limit number of records lets you want to insert only 1000 records in table . We can restrict number of rows, but need to add a column on which we can add some constraint ... check below example.! CREATE TABLE TAB_1000_ROWS AS SELECT ROWNUM COL1 FROM DUAL CONNECT BY ROWNUM <1001; ALTER TABLE TAB_1000_ROWS ADD CONSTRAINT CHECK_CONST CHECK (COL1 BETWEEN 1 AND 1000); ALTER TABLE TAB_1000_ROWS MODIFY COL1 NUMBER NOT NULL; ALTER TABLE TAB_1000_ROWS ADD CONSTRAINT UNIQUE_COL1 UNIQUE (COL1); -- or we can also use sequence with max as 100 and no-cycle! after insertion of 100 values it wont allow any new values to get inserted! will throw check or unique constraint! 

How to find distinct from number of list in string

How to find distinct from number of list in string in SQL Solution: SELECT LTRIM(H,',') OUTPUT FROM (SELECT sys_connect_by_path(K,',') H, L val FROM (SELECT K, ROW_NUMBER() OVER (ORDER BY K) L FROM (SELECT UNIQUE TO_NUMBER(REPLACE(SUBSTR(G,1,INSTR(G,',',1)),',','')) K FROM (SELECT B, J, A, (LTRIM(SUBSTR(A,B,J),',')) G FROM ( SELECT DISTINCT b, LEAD(b)over (order by b ASC) j, A FROM (SELECT instr(a,',',level)b, A FROM (SELECT ('1,2,0,2,432,445,3,3,-1,10099,-2,0.32,0.3432,.3432,4,4,5,6,0.32,-2,432,32,21029,10099,3209839') ||',' a FROM dual ) CONNECT BY level <=LENGTH(A)+1 ORDER BY b ) ) WHERE B<>J ORDER BY B ) ORDER BY 1 ) ORDER BY K ) WHERE connect_by_isleaf=1 START WITH L =1 CONNECT BY L = prior L+1 );

Interview questions for sql DBA

1.What are Differences in Delete & Truncate . 2.What are Differences in UNIQUE and Primary key ? 3. What are the agents involved in replication 4.Which Types of clusters and how many ips are required to install failover cluster? 5.Configuration of logshipping and DB mirroring. 5.What are Types of backups and backup scenario? 6.What is deadlock and blocking? 7.Differences between clustered and non clustered indexes? 8.Why SQL Server Agent is used? 9.What are Types of System databases 10.What are the steps for restoring a database?