![]() The code syntax for UNIQUE is quite similar to that of PRIMARY KEY and can be used interchangeably. Unlike primary key, there can be multiple unique constraints defined per table. This provides uniqueness for the column(s) and helps identify each row uniquely. FOREIGN KEY - Ensures referential integrity for a record in another table.Ī UNIQUE constraint ensures that all values in a column are different.PRIMARY KEY - Uniquely identifies each record in a table.INDEX - Indexes a field providing faster retrieval of records. ![]() UNIQUE - Ensures unique values to be inserted into the field.DEFAULT - Automatically assigns a default value if no value has been specified for the field.CHECK - Verifies that all values in a field satisfy a condition.NOT NULL - Restricts NULL value from being inserted into a column.It can be applied for single or multiple fields in an SQL table during the creation of the table or after creating using the ALTER TABLE command. What are Constraints in SQL?Ĭonstraints are used to specify the rules concerning data in the table. The columns in a table are called fields while the rows can be referred to as records. Columns can be categorized as vertical and rows as horizontal. Differentiate between commit and checkpoint.Ī table is an organized collection of data stored in the form of rows and columns. Does PostgreSQL support full text search? How will you take backup of the database in PostgreSQL? ![]() How do you perform case-insensitive searches using regular expressions in PostgreSQL? What is the main disadvantage of deleting data from an existing table using the DROP TABLE command? What can you tell about WAL (Write Ahead Logging)? How do you check the rows affected as part of previous transactions? What do you understand by command enable-debug? What do you understand by multi-version concurrency control? Can you explain the architecture of PostgreSQL? What are ACID properties? Is PostgreSQL compliant with ACID? How can you delete a database in PostgreSQL? How can you get a list of all databases in PostgreSQL? What is the capacity of a table in PostgreSQL? What is the importance of the TRUNCATE statement? What are partitioned tables called in PostgreSQL? How can we start, restart and stop the PostgreSQL server? What is the command used for creating a database in PostgreSQL? How will you change the datatype of a column? How to create empty tables with the same structure as another table? What is Collation? What are the different types of Collation Sensitivity? What are the differences between OLTP and OLAP? What is User-defined function? What are its various types? ![]() What is the difference between DELETE and TRUNCATE statements? What is the difference between DROP and TRUNCATE statements? What are the TRUNCATE, DELETE and DROP statements? What are the various forms of Normalization? List the different types of relationships in SQL. What are UNION, MINUS and INTERSECT commands? What are some common clauses used with SELECT query in SQL? What is the difference between Clustered and Non-clustered index? What is an Index? Explain its different types. What is a Join? List its different types. What is the difference between SQL and MySQL? What is RDBMS? How is it different from DBMS? Drop the foreign key constraint by its name ALTER TABLE dbo. Now you can alter the child table and drop the constraint by its name using the following statement: OBJECT_NAME (referenced_object_id ) = 'states' WHERE OBJECT_SCHEMA_NAME (referenced_object_id ) = 'dbo' AND OBJECT_SCHEMA_NAME (parent_object_id ) + '.' + OBJECT_NAME (parent_object_id ) AS 'Child Table' FROM sys. Find foreign keys referencing to dbo.states table SELECT name AS 'Foreign Key Constraint Name' , # Msg 3726, Level 16, State 1, Line 1 # Could not drop object 'states' because it is referenced by a FOREIGN KEY constraint.įor a given parent table, you can use the following query to get foreign key constraint names and the referencing table names: Now if you try to remove the parent table states, the DROP TABLE statement fails: Assume there is a parent and child tables in SQL Server:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |