Trending December 2023 # Cassandra Table Example: Create, Alter, Drop & Truncate Table # Suggested January 2024 # Top 12 Popular

You are reading the article Cassandra Table Example: Create, Alter, Drop & Truncate Table updated in December 2023 on the website Achiashop.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested January 2024 Cassandra Table Example: Create, Alter, Drop & Truncate Table

The syntax of Cassandra query language (CQL) resembles with SQL language.

How to Create Table in Cassandra

Column family in Cassandra is similar to RDBMS table. Column family is used to store data.

Command ‘Create Table’ is used to create column family in Cassandra.

Syntax Create table KeyspaceName.TableName ( ColumnName DataType, ColumnName DataType, ColumnName DataType . . . Primary key(ColumnName) ) with PropertyName=PropertyValue;

1. Primary key: There are two types of primary key.

Single Primary Key: Single primary key is specified by the following syntax.

Syntax Primary key (ColumnName)

In the single primary key, there is only a single column. That column is also called partitioning key. Data is partitioned on the basis of that column. Data is spread on different nodes on the basis of the partition key.

2. Compound Primary Key: Compound primary key is specified by the following syntax.

Syntax Primary key(ColumnName1,ColumnName2 . . .)

In above syntax, ColumnName1 is the partitioning key and ColumnName2 is the Clustering key. Data will be partitioned on the basis of ColumnName1 and data will be clustered on the basis of ColumnName2. Clustering is the process that sorts data in the partition.

3. Compound Partitioning key: Compound partitioning key is specified by the following syntax.

Syntax Primary Key((ColumnName1,ColumnName2),ColumnName3...))

In above syntax, ColumnName1 and ColumnName2 are the compound partition key. Data will be partitioned on the basis of both columns ColumnName1 and ColumnName2 and data will be clustered on the basis of the ColumnName3. If you have too much data on the single partition. Then, compound partitioning key is used. Compound partitioning key is used to create multiple partitions for the data.

With Clause

“With clause” is used to specify any property and its value for the defined table. For example, if you want to compress Cassandra table data. You can set compression property by specifying compression algorithm property value in “With clause.”

Example

Here is the execution of the command ‘Create table’ that will create table name ‘Student’ in the keyspace ‘University.’

After successful execution of the command ‘Create table’, table ‘Student’ will be created in the keyspace ‘University’ with columns RollNo, Name and dept. RollNo is the primary key. RollNo is also a partition key. All the data will be in the single partition.

Cassandra Alter table

Command ‘Alter Table’ is used to drop column, add a new column, alter column name, alter column type and change the property of the table.

Syntax

Following is the syntax of command ‘Alter Table.’

Alter table KeyspaceName.TableName + With propertyName=PropertyValue Example

Here is the snapshot of the command ‘Alter Table’ that will add new column in the table Student.

After successful execution of the command ‘Alter Table’, a new column ‘Semester’ with ‘int’ data type will be added to the table Student.

Here is the screenshot that shows the updated Student table.

Cassandra Drop Table

Command ‘Drop table’ drops specified table including all the data from the keyspace. Before dropping the table, Cassandra takes a snapshot of the data not the schema as a backup.

Syntax Drop Table KeyspaceName.TableName Example

Here is the snapshot of the executed command ‘Drop Table’ that will drop table Student from the keyspace ‘University’.

After successful execution of the command ‘Drop Table’, table Student will be dropped from the keyspace University.

Here is the snapshot that shows the error returned by the Cassandra when tried to access Student table that does not exist.

Cassandra Truncate Table

Command ‘Truncate table’ removes all the data from the specified table. Before truncating the data, Cassandra takes the snapshot of the data as a backup.

Syntax Truncate KeyspaceName.TableName Example

There are three records in the table Student. These are the records in the table.

Here is the snapshot of the executed command ‘Truncate table’ that will remove all the data from the table Student.

After successful execution of the command ‘Truncate Table’, all the data will be removed from the table Student.

Here is the snapshot of the database state where there are no records in the table Student.

You're reading Cassandra Table Example: Create, Alter, Drop & Truncate Table

Learn The Examples Of Truncate Table Statement

Introduction to SQL TRUNCATE()

TRUNCATE in standard query language (SQL) is a data definition language (DDL) statement used to delete complete data from a database table without deleting it. It frees up space or empties space in the table. However, we should note that TRUNCATE TABLE statements might need to be roll backable in many SQL databases. Also, being a DDL statement, the TRUNCATE table statement does not require a commit at each step; it automatically fires a commit at the end of the execution of the statement. Hence, we should be careful while using it.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Syntax and Parameters

The basic syntax for using a SQL TRUNCATE TABLE statement is as follows :

TRUNCATE TABLE table_name;

Table_name: It is the name of the table whose records or rows you want to delete permanently.

How does the TRUNCATE TABLE statement work in SQL?

TRUNCATE TABLE statement in SQL works by zeroing out a file in the database, i.e., after running a TRUNCATE statement on an existing table, the table becomes empty and hence does not hold any row records. It resets the table to zero entries.

However, its structure, columns, indexes, constraints, relationships, views, etc., are preserved after truncating the table. The entire operation is like erasing data from the table but keeping the table intact.

TRUNCATE in Data Definition Language (DDL) is equivalent to DELETE in Data Manipulation Language (DML). The only difference is that the latter can be rolled back, but the first cannot. However, TRUNCATE is faster than DELETE because it usually bypasses the transaction system. It is not logged (it can vary across SQL databases) and does not follow predicates and hence seems to be faster than the DELETE operation. DELETE is a safer and slower operation.

Examples of SQL TRUNCATE()

Here are a few examples to explain the TRUNCATE TABLE statement in great detail.

Example #1

Simple SQL query to illustrate the function of the TRUNCATE TABLE statement.

To understand the SQL TRUNCATE TABLE, let us consider a “customers” table. The data in the table looks like this.

Command:

SELECT * FROM public.customers

Output:

Next, let us run the TRUNCATE TABLE statement on the customer’s table to remove all its records. We can do so using the following SQL query.

Command:

TRUNCATE TABLE customers;

Output:

We can see in the figure below that the TRUNCATE TABLE statement has removed all the records in the customer’s table. However, all the columns, relationships, indexes, and table structures have been kept safe.

Command:

SELECT * FROM customers;

Output:

Example #2

For this, let us consider two tables, “customer_details” and “students”. The table structure and the data in them look something like this. Records in the “Customer_details” table are as follows:

Command:

SELECT * FROM public.customers_details

Output:

Records in the “Students” table are as follows:

SELECT * FROM public.students

Output:

Next, we will run the TRUNCATE TABLE on the customer_details table and DROP TABLE on the student’s table, and then we will check the difference.

Command:

TRUNCATE TABLE customer_details;

Output:

Command:

Output:

We can observe from the images above that the DROP TABLE statement is faster than the TRUNCATE TABLE statement in SQL.

Now let us check what happened to the two tables after truncating and dropping, respectively.

Command:

SELECT * FROM customer_details;

Output:

Command:

SELECT * FROM students;

Output:

From the above two images, we can observe that in the TRUNCATE statement, the table structure is preserved; only the data/records in the table have been removed. Whereas in the case of the DROP TABLE statement, the entire table has been removed from the database.

Conclusion

TRUNCATE TABLE in SQL is a Data Definition Language (DDL) statement that empties an existing table by removing all the records while preserving table columns, privileges, indexes, views, constraints, relationships, etc. It is equivalent to but faster than the DELETE statement in SQL. However, unlike DELETE, it cannot be rolled back.

Recommended Articles

We hope that this EDUCBA information on “SQL TRUNCATE()” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

Statement Of Retained Earnings Example

Definition of Statement of Retained Earnings

Download Corporate Valuation, Investment Banking, Accounting, CFA Calculator & others

Examples of Statement of Retained Earnings (With Excel Template)

Let’s take an example to understand the calculation of a Statement of Retained Earnings in a better manner.

You can download this Statement of Retained Earnings Example Excel Template here – Statement of Retained Earnings Example Excel Template

Statement of Retained Earnings – #1

FRY ltd had an opening retained earnings balance of $14,000 carried forward from the year 2023. In 2023, it earned an additional $54,000 after all expenses were paid. It was then decided that $30,000 would be paid to the shareholders as dividends. Below is the calculation involved in checking the retained earnings at the end of the year 2023:

Statement of Retained Earnings – #2

Chan Ltd started 2023 with an opening retained earnings balance of $2,340. It earned a net income of $14,890 during the year and paid a dividend to preferred shareholders amounting to $4,210 and the equity shareholders worth $3,640. There was also a prior period adjustment of $2,400. The retained earnings at the end of the year 2023 will be calculated as below:

The entity does not consider retaining earnings as a major source of funds. From the profit it earned during a year, it had a dual obligation to both the preferred and the equity shareholders, bringing down the amount that could have been retained. Also, prior period adjustments play a part in the ultimate retention. Companies must rectify any items erroneously passed in the previous year as prior period adjustments in the current year. They could either bring down or increase the profit in the present year.

Statement of Retained Earnings – #3

For a statement of retained earnings, apart from arriving at the closing earnings balance through opening earnings and profits for the year, it is also useful if one could calculate the cost of retained earnings. Surprisingly, retaining the profits instead of distributing them to shareholders as dividends is associated with an opportunity cost. Also, if an entity retains earnings instead of distributing them to the shareholders, it risks displeasing them. Therefore, it is imperative that a good return may come up using the earnings.

In general, if no other specific factors and variables are mentioned, the cost of retained earnings equals the cost of equity multiplied by a reduction in the shareholder’s tax rate. This assumption implies the absence of floatation costs.

This cost of retained earnings should be compared with the cost of raising debt from the market, and the decision to limit the retention percentage should be taken accordingly. Suppose the cost of raising debt is lower. In that case, the funds are easily available, and unlike retained earnings, it provides the taxation benefit to the entity; then, the preferred method of obtaining funds should be from external sources.

Conclusion

The statement of retained earnings is a good indicator of the health of the company and the ability to be independent in the future. Organic growth using the funds generated by itself is always a preferred form of growth over utilizing funds from outside. But, the quantum of the earnings cannot be a definitive conclusion. Some of the industries which are capital intensive depend a lot more on the retained earnings portion than the outside funds.

Retention is also a direct factor in the policy of the entity. Even though there are adequate profits, companies commonly have limited retained earnings as they distribute most of the funds among the shareholders as dividends. Again, market conditions give a direction to retained earnings. Emphasizing retained earnings becomes necessary if borrowing becomes expensive, even with limited profits.

Generally, the following become determinants in the retained earnings policy

The debt cost associated with raising funds from external sources

The dividend policy needs to be adopted in the foreseeable future. If the policy is a populist catering to large dividends, the entity has to cut down on the portion of retention.

For many concerns, the government or regulatory policies governing the entity become the primary source of checks to determine if the retained earnings are within limits.

Lastly, the nature of the industry to which the entity belongs and the traditional method of getting the funds plays a major role in making the retention decision.

Recommended Articles

This has been a guide to the Statement of Retained Earnings Example. Here we discuss the introduction and top 3 Examples of a Statement of Retained Earnings, a detailed explanation, and a downloadable Excel template. You can also go through our other suggested articles to learn more –

Definition, Formula, Calculation, & Example

What is Marginal Costing?

Marginal costing is an accounting measure determining the cost of producing additional output units. For example, a company produces 60 units of a product at $1.6 per unit for a total of $100. They receive an order of 90 units which the company makes for $140. In this case, the marginal cost for each additional unit becomes ($140-$100)/(90-60), which is $1.3 per unit.

In other words, it refers to the adjustments in total when producing one more unit of the product/service. It considers both fixed and variable costs for the process.

Key Highlights

Marginal costing, in economic terms, describes how the changes in production quantity reflect production costs.

The equation to calculate this metric is by dividing the difference in costs by the change in produced quantity.

Its prominent characteristics are the determination of a firm’s profitability along with its profit-maximizing level of production, valuation of its stocks, and more.

Although this measure helps businesses with budget planning and decision-making, cost segregation is one of its complex factors.

How to Calculate Marginal Costing Using Formula?

Start Your Free Investment Banking Course

1. Determine the Quantity Change

Initially, the company needs to ascertain the number of units they produce on a regular scale. It will be the number of standard units.

In case of variation in the standard quantity, the company needs to record the number of units of production.

Subtracting the original quantity the firm usually produces from the quantity value containing additional units gives the change in quantity.

For example, a firm usually produces 100 units of a product. For custom orders, they make 160 units. Therefore, they had to build 60 additional units.

Formula: Change in Quantity = Quantity Including Additional Unit – Normal Unit Quantity

2. Determine the Cost Change

Determine the total cost of production by summing the variable and fixed prices for a given units

Fixed costs do not change throughout the evaluation period. Capital outlays (such as equipment), and rental fees are fixed costs

Variable costs can change depending on the circumstances. Services, employee payroll, and raw materials are examples of variable costs

After computing total costs for standard units of production and additional units, less the costs of producing standard units from the new price, including the additional units

For example, a company produces its standard unit of products at $500. It costs the company $700 to make more than the standard unit. Therefore, the total cost will be $200.

Formula: Change in total cost = Additional Unit Production Cost – Normal Unit Production Cost

3. Calculate the Marginal Costing

Once you have the change in total cost and quantity, divide them to derive each additional unit’s marginal cost

It is usually lower than the average unit cost, but it can also be equal.

Formula: Marginal Costing = Change in Total Cost / Change in Quantity

Marginal Costing Example

You can download this Marginal Costing Template here – Marginal Costing Template

Example #1:

A manufacturing company’s product price is $2.5. After receiving a custom order, they record a change in their quantity and production costs as follows,

 Change in quantity = 15,000

 Change in total costs = $36,000

Calculate the marginal cost of each additional unit.

Given,

Implementing the formula,

The marginal cost for each extra unit is $2.

Example #2:

Company ABC produces 50,000 units every year at the cost of $220,000. In 2023, it produced additional units totaling 64,000 at $270,000. Calculate the additional unit’s marginal rate.

Calculating the change in the measures,

Implementing the formula,

Features & Characteristics of Marginal Costing

It can determine the impact of variable costs on production volume

The contribution of each product or department serves as the foundation for determining their profitability

It can help with the pricing of products to elevate profit margins at minimal costs

Values the stock of work in progress and finished products solely on variable costs

It is a helpful technique that contributes to analyzing profits concerning cost and capacity. Additionally, it also splits semivariable costs into fixed and variable components

It affects profit despite no change in the selling price. With an increase in production, the average cost falls, and the average & total profit rises.

Marginal Costing Assumptions

Following are the assumptions,

Segregation between fixed and variable costs is attainable

The cost to produce a unit is constant. However, this assumption is not always valid because sometimes there are variable costs such as materials and labor.

The price to sell the product remains the same before and after the production of additional units

The only metric that modifies the costs is the change in the quantity of the output.

Absorption Costing vs. Marginal Costing

Absorption Costing

Marginal Costing

The products costs include both variable and fixed costs The product costs only considers variable costs, while fixed costs are for the period

The allocation of the costs is for each unit of production The cost allocation is separate for the base units and the additional units

It is on a per-batch basis, i.e., it considers all costs incurred for producing one more batch It uses a per-unit basis, i.e., it considers the additional cost incurred for making one more unit

The overhead costs are considered and range from production and administration to costs for distribution. It takes into account fixed and variable overhead costs.

Advantages & Limitations

Advantages

Limitations

It makes it easier to calculate the cost of sales, resulting in greater accuracy in profit calculation It isn’t easy to separate costs into fixed and variable, as their distinction is only valid in the short term.

The method of valuing shares becomes very simple

Companies manufacturing various products can prepare a comparative profitability statement which assists in informed product decisions One cannot determine the price solely based on the contribution

It can help determine the price of your product/service to make a profit. The sales function is given more weight over the production function. However, a business’s efficiency valuation should combine the sales and production functions.

Marginal Costing Importance

A clear division of costs into fixed and variable elements makes the flexible budget control system simple and effective, allowing for more practical cost control

It aids in profit planning through the use of balance sheets and profit charts

It is an effective tool for determining efficient sales, production policies, or pricing decisions, especially when the business is in a slump.

Frequently Asked Questions(FAQs)

Answer: Marginal costing is a way for companies to determine whether it’s worth producing another product. It helps them budget, forecast, and assess their profit on each product to make product-related decisions.

Answer: Marginal-cost pricing is a strategy where companies sell a product/service where the cost of an additional unit is meager. Firms apply this when they detect a decline in demand for a product. For example, if the marginal cost of a product is $5 and the original selling price is $10, the firm may move the selling price to $6 or $7. They believe lower profit is better than no product profit.

Answer: The determination of the marginal cost is different from that of the average basket. The average cost divides the total price by the total produced units to determine the price per unit. On the other hand, marginal cost is a generalized cost per additional unit when creating one more element.

Answer: It represents the cost change in terms of a graph. The graph in the short run is U-shaped, where the x-axis and y-axis represent the quantity and costs, respectively.

Recommended Articles

This article explains everything about Marginal Costing. Read the following articles to learn more,

The Table Keyword In Dax Studio: Basic Examples

In this tutorial, you’ll learn about the TABLE keyword in DAX Studio. The TABLE keyword allows you to create tables inside your DAX query.

This is a continuation of a series of tutorials on the different keywords that you can use when creating DAX queries. Before diving into this topic, make sure to read first on the DEFINE and MEASURE keywords.

To use this keyword, first write DEFINE followed by TABLE. Then, provide the name of the table you want to create. In this example, the table’s name is ModelStats.

A specific function is used for this query: the COLUMNSTATISTICS () function. This function can be used to quickly create metadata on every table in your data model. This function is not available in the DAX in Power BI; it’s entirely unique to DAX Studio.

To view the table, write EVALUATE ModelStats.

After you run this query, you’ll get a table showing all the tables and statistics of each table in your data model.

You can also add another column by using the ADDCOLUMNS function. In this case, the column’s name is “Random” and it shows random numbers generated by DAX Studio using the RAND function.

Let’s go into a more realistic example. This is the same example used in the MEASURE keyword tutorial. It’s focused on a hypothetical business with “trendy” and “boring” products.

In this case, the goal is to segregate the Products table into 2 categories. The first table is for the TrendyProducts, while the second is for the BoringProducts.

For the TrendyProducts table, first DEFINE what are TrendyColors. In this instance, they’re Red, Blue, and Pink. Then, you need to inject that filter into the filter context. To do so, you need to use the CALCULATETABLE function.

Notice that the VAR function is used. This is to differentiate between the variables and the name of the table.

Next, create a variable for the Result. For this variable, create a new column using the ADDCOLUMNS function and name it “Description.” The Description column will identify which rows belong to the Trendy Products. Then, RETURN the Result.

You can see that the table is returning 383 rows that are marked as Trendy Products.

Now the same logic also applies for the BoringProducts table. You can copy the code and paste it after RETURN.

So instead of TABLE TrendyProducts, replace it with TABLE BoringProducts. For the CALCULATETABLE argument, write the NOT function. And then, change the column name to “Boring.”

Next, EVALUATE the BoringProducts table to view it.

You can see that the boring products return 2,134 rows. You can also see in the Description column that it only contains “Boring.”

The next thing you can do is join these two tables together using the UNION keyword.

Now, one would think that you can just write a new TABLE keyword with the UNION function to combine the two tables together.

However, it isn’t possible for this case since the BoringProducts code contains the TrendyProducts table. If you attempt to run this query, you’ll get an error.

You can’t use a query table within another query table in DAX Studio.

Instead, you should place the UNION syntax after EVALUATE.

If you run this, you’ll get a table containing both the Trendy and Boring products. You can see that this table contains 2517 rows.

This next example shows how to create a Dates table in your data model. Open a new blank query. Before anything else, let’s first try out the TABLE keyword with the CALENDAR and DATE functions. This query is simply evaluating the dates in between January 1, 2007 and December 31, 2007.

You can see that the results show all the dates in between what was specified in the query. To create more columns in the Dates table, use the GENERATE function over the current CALENDAR code. Then, use the ROW function to segregate different data within the Dates table.

The [Date] column used in this query is from the CALENDAR function. Notice also that a variable VAR CurrentDate is used. This variable stores the value that’s being accessed from the row context. That value is then returned inside the row function.

This is done to simplify the code. So instead of using the [Date] column reference, you can use the variable you declared. You can add more columns in your Dates table according to your needs.

Another thing you can do with the Dates table you created is adding in the SUMMARIZECOLUMNS function.

After EVALUATE, use SUMMARIZECOLUMNS and then COUNTROWS to count the number of rows belonging to your Calendar Year Number.

After you run this, you can see that the table reports 365 rows belong to the year 2007. You can try and experiment with your current query.

For instance, you can change the upper bound of the end date from 2007 to 2009. If you run this, you’ll see that the table now shows rows for the years 2007, 2008, and 2009.

If for example, you want to add another column that shows the first date of the table, use the FIRSTDATE function.

Similarly, use the LASTDATE function to identify the last date of each row.

To get the Total Rows in your Dates tables, use the CALCULATE function with COUNTROWS. And then, use REMOVEFILTERS to remove the filter context from the Dates table you created using SUMMARIZECOLUMNS.

After running the query, you can see that there’s a new column showing the total count of rows available in the Dates table.

Along with DEFINE and MEASURE, the TABLE keyword is vital when creating queries in DAX Studio. It helps simplify the process of creating tables.

This tutorial shows basic examples of how to use the TABLE keyword. It’s important to learn the basics as this helps in understanding more complex queries which are more common when real-world applications are involved.

Enterprise DNA Experts

How To Tactfully Drop A Client

The adage “the customer is always right” isn’t always true. Demanding and unreasonable clients can reach a point where they’re not worth your time.

Before letting clients go, try to resolve conflicts diplomatically, using tactful and open communication strategies.

If a client relationship is untenable, be honest, professional, and polite when parting ways.

This article is for service-based business owners grappling with a difficult client and considering severing the relationship.

Most service-based businesses have encountered a nightmare client at some point. This person makes outrageous demands of your team and expects them to be met immediately. They don’t respect the due date on the invoice and refuse to pay you on time. And when it comes to communication, this client either pesters you 24/7 or can’t be reached at all.

The old cliche may say the customer is always right, but some problematic clients may not be worth your time. Although you may be hesitant to drop (or “fire”) a client, the temporary loss of income could be in your business’s best interest in the long run.

Here’s a look at what to do when faced with a challenging client, when to know it’s time to part ways, and how to extricate yourself politely and professionally.

Key Takeaway

If you have a consumer-focused business, some strategies for dealing with difficult customers are simply listening, empathizing, lowering your voice and staying calm.

How to resolve conflicts with clients diplomatically

If you’re fed up with a client, it may be tempting to let them go immediately. However, while some clients may be annoying, you may not want to give up on the relationship so fast. Here are a few tips for working things out with your client.

1. Figure out what the problem is with your nightmare client.

Step back from the situation and figure out what the issue truly is with your problematic client. Are they really unbearable to work with or negatively impacting your company’s bottom line? Or is there just something about their personality that rubs you the wrong way?

If the problem comes down to clashing personalities, there may be other arrangements to make. Perhaps another team member could take over the lead role with that client – or maybe you can resolve to tolerate and deal with the individual until their contract runs out.

2. Set boundaries with your difficult client.

It’s always a good idea to reassess your client boundaries regularly. For instance, if you have a client who calls you at all hours of the day and night, you may need to reiterate when you’re willing to take calls and when you aren’t. As another example, if you have a client who regularly asks for revisions or tasks beyond the scope of your agreement, it may be helpful to review the terms of your initial contract.

Firmly but politely restating your boundaries may be enough to salvage the working relationship. If the client refuses to respect your boundaries, this can be a clear sign that it’s time to end the working relationship.

Tip

If you need help fielding client calls, consider using a call center or answering service. We’ll help you find the right one with our comparison of the best call centers and answering services for businesses.

3. Communicate openly with your client.

Your clients can’t read your mind; they won’t know if something they’re doing is bothering you unless you tell them. You’re not doing yourself or them a favor by pretending that everything is fine when it isn’t.

If something is bothering you about your working relationship, you owe it to your client to be honest about it. This is especially true if it’s a long-term client; in this case, you probably want to do everything you can to repair the relationship.

Tip

To improve communication with clients, respond to complaints immediately, implement a two-way communication channel, and monitor social media platforms to find out what others are saying about your business.

Update the detailed information about Cassandra Table Example: Create, Alter, Drop & Truncate Table on the Achiashop.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!